我已经在Kubernetes上部署并公开了一个应用,但是请求的结果不一致 - 有时返回<200>
,有时则是错误 - 可能是[Errno -2] Name or service not known
或者[Errno -3] Temporary failure in name resolution
。
请求内容:
import requests
requests.get("http://someapp:1337")
错误信息:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='someapp', port=1337): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnecti
on object at 0x7eff4c274fa0>: Failed to establish a new connection: [Errno -2] Name or service not known'))
然而,当我使用IP发出请求时,它总是返回<200>
import requests
requests.get("http://10.90.34.73:1337") # --> <200>
kubectl describe:
Name: someapp
Namespace: app
Labels: <none>
Annotations: <none>
Selector: app=someapp
Type: ClusterIP
IP Families: <none>
IP: 10.103.244.53
IPs: 10.103.244.53
Port: <unset> 1337/TCP
TargetPort: 1337/TCP
Endpoints: 10.90.34.73:1337
Session Affinity: None
Events: <none>
由于问题不稳定,我不确定接下来该怎么做。有什么想法吗?
{SVCNAME}_SERVICE_HOST
和{SVCNAME}_SERVICE_PORT
环境变量构建请求而不使用服务名称,并且使用IP进行连接每次都能立即成功(> 1秒)。 - jakubmatyszewski