Python: unable to access kubernetes api from within pod with python client, can do so with curl

Created on 7 Oct 2019  路  1Comment  路  Source: kubernetes-client/python

What happened (please include outputs or screenshots):

I am able to access the kubernetes API from within the pod via curl

KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) && curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" https://$KUBERNETES_SERVICE_HOST:$KUBRNETES_PORT_443_TCP_PORT/api/v1/namespaces -I
However doing the same with the python client it will hang and crash the pod

What you expected to happen:

A list of namespaces is returned

How to reproduce it (as minimally and precisely as possible):
Enter your pod with
kubectl exec -it /bin/bash

Run this script to replicate the curl command

with open('/var/run/secrets/kubernetes.io/serviceaccount/token') as f:
    token = f.read()

host = os.environ['KUBERNETES_SERVICE_HOST']

configuration = kubernetes.client.Configuration()
configuration.api_key['authorization'] = token
configuration.host = host

api_instance = kubernetes.client.CoreV1Api(kubernetes.client.ApiClient(configuration))
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)

try: 
    api_response = api_instance.list_namespace(pretty=pretty, timeout_seconds=3)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling CoreV1Api->list_namespace: %s\n" % e)

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version):
    Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.7-gke.24", GitCommit:"2ce02ef1754a457ba464ab87dba9090d90cf0468", GitTreeState:"clean", BuildDate:"2019-08-12T22:05:28Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"}
  • OS (e.g., MacOS 10.13.6): Ubuntu 18.04.1 LTS (pod)
  • Python version (python --version): Python 3.6.8

  • Python client version (pip list | grep kubernetes): kubernetes (10.0.1)

kinbug

Most helpful comment

Closed. I was able to resolve by disabling ssl

configuration.verify_ssl=False

>All comments

Closed. I was able to resolve by disabling ssl

configuration.verify_ssl=False

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tdigangi picture tdigangi  路  4Comments

palnabarun picture palnabarun  路  4Comments

zmunro picture zmunro  路  3Comments

avarf picture avarf  路  4Comments

karmab picture karmab  路  5Comments