8

I have setup Official Kubernetes Python Client (https://github.com/kubernetes-client/python).

I am running Python code to connect to a Kubernetes cluster and it's throwing an error:

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',))

Installed requirements:

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 is working fine with the same config $HOME/.kube/config and same proxy settings.

Below is my code:

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)
5
  • 1
    Have you tried executing kubectl from the host the python is being executed? Commented Apr 18, 2019 at 11:01
  • @Crou, yes, kubeclt works fine on the same host the python code is being execute. The proxy setting same for both kubectl and python execution. I also tried kubernetes official golang client. It works fine. I am facing issue only with python setup. Is it problem with the python Version Iam using ? Commented Apr 19, 2019 at 5:42
  • Which version of the Python client and Kubernetes are you using? Commented Apr 19, 2019 at 7:57
  • @char Kubernetes Version: v1.11.8 ----------------------- Kubernetes-Python client version: 10.0.0 $pip show kubernetes Name: kubernetes Version: 10.0.0-snapshot Summary: Kubernetes python client ----------------------- Commented Apr 19, 2019 at 9:58
  • Maybe open an issue on the python client repo? Commented Apr 19, 2019 at 18:31

2 Answers 2

4

In my case simply loading the config via load_kube_config didn't work as well. I ended up first running a proxy:

kubectl proxy --port=8888

and then changing the host using the Configuration object:

configuration = client.Configuration()
configuration.host = "localhost:8888"
api_client = client.CoreV1Api(client.ApiClient(configuration))
Sign up to request clarification or add additional context in comments.

Comments

0

You need to specify the host ID for your client. You can find this in AI Platform Pipelines >> Settings. The code will look similar to this:

import kfp
client = kfp.Client(host='###########-dot-us-east1.pipelines.googleusercontent.com')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.