J'ai une application python exécutée sur une machine virtuelle, c'était un héritage, et maintenant je migre vers un Kubernetes.
J'utilise le package influxdb==5.2.3
, En me connectant à ce formulaire Influx(Host=r'influx_Host', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=True)
. Ce python script appelle un InfluxBD en utilisant un certificat SSL et lorsque je l'exécute directement en utilisant python app.py
Fonctionne bien, mais le problème est quand:
Traceback (most recent call last):
File "app.py", line 591, in <module>
get_horas_stock()
File "app.py", line 513, in get_horas_stock
df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
File "/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py", line 82, in multiple_query_to_df
resultado = self.__cliente.query(";".join(queries))
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 445, in query
response = self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 302, in request
raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: Client sent an HTTP request to an HTTPS server.
Je comprends que, de l'intérieur du conteneur, le script utilise https pour appeler Influx, mais je pense que la connexion est redirigée à l'extérieur du conteneur en utilisant Http et perd toute configuration SSL, pourquoi? Je ne sais pas.
J'ai essayé de déployer sur Kubernetes en pensant que j'obtenais la même erreur, mais cela a changé.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 360, in _error_catcher
yield
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 442, in read
data = self._fp.read(amt)
File "/usr/local/lib/python3.8/http/client.py", line 454, in read
n = self.readinto(b)
File "/usr/local/lib/python3.8/http/client.py", line 498, in readinto
n = self.fp.readinto(b)
File "/usr/local/lib/python3.8/socket.py", 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 "/usr/local/lib/python3.8/site-packages/requests/models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 378, in _error_catcher
raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "app.py", line 591, in <module>
get_horas_stock()
File "app.py", line 513, in get_horas_stock
df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
File "/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py", line 82, in multiple_query_to_df
resultado = self.__cliente.query(";".join(queries))
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 445, in query
response = self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 274, in request
response = self._session.request(
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 686, in send
r.content
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 753, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
Je ne sais pas si cela est lié à l'erreur précédente.
Dockerfile
FROM python:3.8.2-buster
WORKDIR /usr/src/app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8080
CMD ["python", "app.py"]
Déploiement de Kubernetes YML
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
J'obtiens la même erreur que j'ai sur Kubernetes, mais en exécutant le script localement, je change la valeur SSL de True à False dans l'appel de service Influx(Host=r'influx_Host', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=False)
.
~$ python3 app.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 360, in _error_catcher
yield
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 442, in read
data = self._fp.read(amt)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 457, in read
n = self.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 501, in readinto
n = self.fp.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", 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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 378, in _error_catcher
raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(54, 'Connection reset by peer')", ConnectionResetError(54, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "app.py", line 1272, in <module>
generate_excels_consumo()
File "/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/calculo_excels.py", line 206, in generate_excels_consumo
df_sector = influx_kpis.multiple_query_to_multiple_df(queries)
File "/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/analitica_py_lib_conexiones/conexion_influx.py", line 126, in multiple_query_to_multiple_df
resultado = self.__cliente.query(";".join(query))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py", line 450, in query
expected_response_code=expected_response_code
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py", line 283, in request
timeout=self._timeout
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 686, in send
r.content
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 753, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(54, 'Connection reset by peer')", ConnectionResetError(54, 'Connection reset by peer'))
Cela semble un problème de réseau. J'ai rencontré un problème plus simple pour me connecter à MongoDB à cause de Proxy. Tout peut se produire ce problème.
Par défaut, chaque conteneur exécuté par Docker possède son propre espace de noms réseau.
Offrant quelques méthodes de solution:
traceroute <cluster-ip>
exécutez cette commande et vérifiez si vous arrivez au cluster à l'intérieur du conteneur d'attachement de conteneur et exécutez la commande docker exec -it container /bin/bash
.export
vérifier les variables d'environnement liées au proxy.curl www.google.com
C'est un très bon document pour comprendre et résoudre le problème de connexion docker.