python-3.x - Kubernetes Python 客户端连接问题

标签 python-3.x kubernetes kubectl kubernetes-python-client

我已经设置了官方 Kubernetes Python 客户端 ( https://github.com/kubernetes-client/python )。

我正在运行 Python 代码以连接到 Kubernetes 集群,但它抛出了 错误 :

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='****', port=6443): Max retries exceeded with url: /api/v1/namespaces/default/pods (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',))



安装要求:
cachetools        3.1.0 ,
certifi           2019.3.9 ,
chardet           3.0.4 , 
google-auth       1.6.3 ,
idna              2.8 ,
ipaddress         1.0.22 ,
kubernetes        10.0.0-snapshot ,
oauthlib          3.0.1 ,
pip               19.0.3 ,
pyasn1            0.4.5 ,
pyasn1-modules    0.2.4 ,
python-dateutil   2.8.0 ,
PyYAML            5.1 ,
requests          2.21.0 ,
requests-oauthlib 1.2.0 ,
rsa               4.0 ,
setuptools        41.0.0 ,
six               1.12.0 ,
urllib3           1.24.1 ,
websocket-client  0.56.0 ,
wheel             0.33.1 
kubectl使用相同的配置工作正常 $HOME/.kube/config和相同的代理设置。

下面是我的代码:
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)

最佳答案

就我而言,只需通过 load_kube_config 加载配置即可也没有用。我最终首先运行了一个代理:

kubectl proxy --port=8888

然后使用 Configuration 更改主机目的:
configuration = client.Configuration()
configuration.host = "localhost:8888"
api_client = client.CoreV1Api(client.ApiClient(configuration))

关于python-3.x - Kubernetes Python 客户端连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55742540/

相关文章:

docker - 如何让kubernetes pod可以访问PostgreSQL Pod

docker - 由于子网管理器故障,导致kubernetes群集中的法兰失败

python - 康威的生命游戏邻居计数

kubernetes - 如何保护 Google Kubernetes Engine (GKE) 中的只读端口 10255?

python django scrapy 将项目返回到 Controller

kubernetes - 作业完成后,K8s 作业(容器)中指定的内存请求/限制会发生什么情况?

nginx - 单个 NGINX-Ingress Controller ,用于在单独命名空间中具有资源的子域

docker - 无法使用 docker ps -a 列出已停止的容器

python - 随机选择一个数字然后随机选择一个更大的数字python代码?

python-3.x - Cron 作业中的 PyAutoGUI