<p>I have a python application running on a virtual machine, were a legacy, and now I'm migrating to a Kubernetes.</p>
<p>I use <code>influxdb==5.2.3</code> package, connecting to this form <code>Influx(host=r'influx_HOST', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=True)</code>. This python script calls an InfluxBD using an SSL certificate and when I run directly using <code>python app.py</code> works well, but, the problem is when:</p>
<h3> I dockerized the script shows me the following error.</h3>
<pre><code>Traceback (most recent call last):
  File &quot;app.py&quot;, line 591, in &lt;module&gt;
    get_horas_stock()
  File &quot;app.py&quot;, line 513, in get_horas_stock
    df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
  File &quot;/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py&quot;, line 82, in multiple_query_to_df
    resultado = self.__cliente.query(&quot;;&quot;.join(queries))
  File &quot;/usr/local/lib/python3.8/site-packages/influxdb/client.py&quot;, line 445, in query
    response = self.request(
  File &quot;/usr/local/lib/python3.8/site-packages/influxdb/client.py&quot;, line 302, in request
    raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: Client sent an HTTP request to an HTTPS server.
</code></pre>
<p>I understand to, from inside the container, the script is using https to call Influx, but I think the connection is redirected outside the container using Http and lose all SSL configuration, why? I don't know.</p>
<h3>I tested deployed on Kubernetes</h3>
<p>I tried to deploy on Kubernetes thinking I get the same error, but it`s changed.</p>
<pre><code>Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.8/site-packages/urllib3/response.py&quot;, line 360, in _error_catcher
    yield
  File &quot;/usr/local/lib/python3.8/site-packages/urllib3/response.py&quot;, line 442, in read
    data = self._fp.read(amt)
  File &quot;/usr/local/lib/python3.8/http/client.py&quot;, line 454, in read
    n = self.readinto(b)
  File &quot;/usr/local/lib/python3.8/http/client.py&quot;, line 498, in readinto
    n = self.fp.readinto(b)
  File &quot;/usr/local/lib/python3.8/socket.py&quot;, line 669, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.8/site-packages/requests/models.py&quot;, line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File &quot;/usr/local/lib/python3.8/site-packages/urllib3/response.py&quot;, line 494, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File &quot;/usr/local/lib/python3.8/site-packages/urllib3/response.py&quot;, line 459, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File &quot;/usr/local/lib/python3.8/contextlib.py&quot;, line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File &quot;/usr/local/lib/python3.8/site-packages/urllib3/response.py&quot;, line 378, in _error_catcher
    raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: (&quot;Connection broken: ConnectionResetError(104, 'Connection reset by peer')&quot;, ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;app.py&quot;, line 591, in &lt;module&gt;
    get_horas_stock()
  File &quot;app.py&quot;, line 513, in get_horas_stock
    df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
  File &quot;/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py&quot;, line 82, in multiple_query_to_df
    resultado = self.__cliente.query(&quot;;&quot;.join(queries))
  File &quot;/usr/local/lib/python3.8/site-packages/influxdb/client.py&quot;, line 445, in query
    response = self.request(
  File &quot;/usr/local/lib/python3.8/site-packages/influxdb/client.py&quot;, line 274, in request
    response = self._session.request(
  File &quot;/usr/local/lib/python3.8/site-packages/requests/sessions.py&quot;, line 533, in request
    resp = self.send(prep, **send_kwargs)
  File &quot;/usr/local/lib/python3.8/site-packages/requests/sessions.py&quot;, line 686, in send
    r.content
  File &quot;/usr/local/lib/python3.8/site-packages/requests/models.py&quot;, line 828, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File &quot;/usr/local/lib/python3.8/site-packages/requests/models.py&quot;, line 753, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: (&quot;Connection broken: ConnectionResetError(104, 'Connection reset by peer')&quot;, ConnectionResetError(104, 'Connection reset by peer'))
</code></pre>
<p>I don't know if is related to the previous error.</p>
<p><a href="https://i.stack.imgur.com/jNjEy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jNjEy.png" alt="enter image description here" /></a></p>
<h3>Edited</h3>
<p>Dockerfile</p>
<pre><code>FROM python:3.8.2-buster

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 8080

CMD [&quot;python&quot;, &quot;app.py&quot;]
</code></pre>
<p>Kubernetes Deployment YML</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-ms
spec:
  replicas: 1
  selector:
    matchLabels:
      ip-service: my-ms
  template:
    metadata:
      labels:
        ip-service: my-ms
    spec:
      containers:
        - name: my-ms
          image: myprivate.azurecr.io/my-ms:latest
          ports:
            - containerPort: 8080
          resources:
            requests:
              cpu: 100m
              memory: 10Mi
      imagePullSecrets:
        - name: tecnoregistry
</code></pre>
<h3>Edited 2</h3>
<p>I get the same error I have on Kubernetes, but running the script locally, I change the SSL value from True to False in the service call <code>Influx(host=r'influx_HOST', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=False)</code>.</p>
<pre><code>~$ python3 app.py
Traceback (most recent call last):
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py&quot;, line 360, in _error_catcher
    yield
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py&quot;, line 442, in read
    data = self._fp.read(amt)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py&quot;, line 457, in read
    n = self.readinto(b)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py&quot;, line 501, in readinto
    n = self.fp.readinto(b)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py&quot;, line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py&quot;, line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py&quot;, line 494, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py&quot;, line 459, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py&quot;, line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py&quot;, line 378, in _error_catcher
    raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: (&quot;Connection broken: ConnectionResetError(54, 'Connection reset by peer')&quot;, ConnectionResetError(54, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;app.py&quot;, line 1272, in &lt;module&gt;
    generate_excels_consumo()
  File &quot;/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/calculo_excels.py&quot;, line 206, in generate_excels_consumo
    df_sector = influx_kpis.multiple_query_to_multiple_df(queries)
  File &quot;/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/analitica_py_lib_conexiones/conexion_influx.py&quot;, line 126, in multiple_query_to_multiple_df
    resultado = self.__cliente.query(&quot;;&quot;.join(query))
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py&quot;, line 450, in query
    expected_response_code=expected_response_code
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py&quot;, line 283, in request
    timeout=self._timeout
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py&quot;, line 533, in request
    resp = self.send(prep, **send_kwargs)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py&quot;, line 686, in send
    r.content
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py&quot;, line 828, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py&quot;, line 753, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: (&quot;Connection broken: ConnectionResetError(54, 'Connection reset by peer')&quot;, ConnectionResetError(54, 'Connection reset by peer'))
</code></pre>

<p>It seems to be a network problem. I faced a similar problem connecting with MongoDB because of Proxy.</p>
<p>By default, each container run by Docker has its own network namespace.</p>
<p>Offering Some Solution Methods:</p>
<ol>
<li><code>traceroute &lt;cluster-ip&gt;</code> perform this command and check whether arrive to cluster inside of container attach container and perform the command <code>docker exec -it container /bin/bash</code>.</li>
<li>Check Proxy. <code>export</code> check environment variables related with proxy.</li>
<li><code>curl www.google.com</code></li>
<li>Try to connect another things in the cluster. For example MySQL, etc. (Once time a machine write me blacklist automatically I tried to solve connection problem 2 day)</li>
<li>Try to use python-slim image. slim image is based from ubuntu.</li>
</ol>
<p>It is very good document to understand and solve docker connection problem.</p>
<p><a href="https://pythonspeed.com/articles/docker-connection-refused/" rel="nofollow noreferrer">https://pythonspeed.com/articles/docker-connection-refused/</a></p>
