What happened (please include outputs or screenshots):
We are using the following code to set up:
from kubernetes import client, config, watch
config.load_kube_config(kubeconfig)
host = config.kube_config.Configuration().host
logging.info("HOST INFO: {}".format(host))
The kubeconfig file has server field set up correctly. This is working with with version 11.0.0 correctly but when we change the version to 12.0.0 then it returns:
HOST INFO: http://localhost
I tried to investigate it and according to kube_config.py file it should be set correctly in _load_cluster_info method but it is not setting up correctly.
What you expected to happen:
Host url to be set correctly in compliance with kube-config file
How to reproduce it (as minimally and precisely as possible):
http://localhostAnything else we need to know?:
Environment:
kubectl version): v1.18.2python --version) 3.7pip list | grep kubernetes) 12.0.0We just encountered the same thing. It seems like this change requires you now to explicitly get the default configuration.
So your line would need to change to something like:
host = config.kube_config.Configuration.get_default_copy().host
Something like this should probably be mentioned in the release notes.
@felixhuettner thanks this solves the issue but using get_default_copy() instead of direct call seems counter-intuitive after setting the configuration from file. (note that this change is also not documented in the readme/examples)
I am also facing this issue.
At the very least, this needs a mention in the changelog so that users know how to fix this.
load_incluster_config() broke too for 12.0.0. It's not clear to me yet how to retain the same mechanism...
My process for setting up my configuration when using load_incluster_config() was:
from kubernetes import client, config, utils
from kubernetes.client import Configuration
config.load_incluster_config()
c = Configuration()
c.assert_hostname = False
Configuration.set_default(c)
which failed to work with for 12.0.0. But if I don't set the new Configuration object as default and only have:
config.load_incluster_config()
it seems to use the correct cluster configuration
/assign
cc @palnabarun @yliaog
I have the same problem,when i use client 8.0.0 get kubernetes version info,It is normal.
from sdk.v8.kubernetes import client
from sdk.v8.kubernetes import config
config.load_kube_config()
configuration = client.Configuration()
configuration.verify_ssl = False
api_client = client.ApiClient(configuration=configuration)
version_api = client.VersionApi(api_client)
print(version_api.get_code())
##output
{
'build_date': '2019-04-22T11:34:20Z',
'compiler': 'gc',
'git_commit': '8cb561c',
'git_tree_state': '',
'git_version': 'v1.12.6-aliyun.1',
'go_version': 'go1.10.8',
'major': '1',
'minor': '12+',
'platform': 'linux/amd64'
}
but when i use client 12.0.0.0,a procedural exception has occurred.
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /version/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9c7cf6f070>: Failed to establish a new connection: [Errno 61] Connection refused'))
It looks like a configuration error,After referring to the above answer, I modified it to
from sdk.v12.kubernetes import client
from sdk.v12.kubernetes import config
config.load_kube_config()
configuration = client.Configuration().get_default_copy()
configuration.verify_ssl = False
api_client = client.ApiClient(configuration=configuration)
version_api = client.VersionApi(api_client)
print(version_api.get_code())
That solved my problem,I think that part of the configuration code logic has changed
@ntavares I confirm this. Have you found a workaround that uses either v12.0.0 or v12.0.1? I am currently using the following code snippet and it fails
from kubernetes import config, client
from kubernetes.client import ApiClient
from kubernetes.dynamic import DynamicClient
config.load_incluster_config()
configuration = client.Configuration.get_default_copy()
k8s_client = ApiClient(configuration=configuration)
dyn_client = DynamicClient(k8s_client)
dyn_client.resources.get(kind="Secret").create(...)

Version: 12.0.1
Python Version: 3.7.6
K8s version: v1.18.9
Most helpful comment
At the very least, this needs a mention in the changelog so that users know how to fix this.