Not having a current context set causes
See original GitHub issueWhen initializing kubectl you typically do something like:
for cluster in clusters
do
kubectl config set-cluster $cluster
kubectl config set-credentials ...
kubectl config set-context ...
That creates a valid config with multiple clusters, but with current-context
set to ""
. If you try to load that config with config.load_kube_config()
the library assumes ""
is a context name and fails with the following:
File "app/main.py", line 131, in get_versions
config.load_kube_config()
File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 739, in load_kube_config
persist_config=persist_config)
File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 707, in _get_kube_config_loader_for_yaml_file
**kwargs)
File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 197, in __init__
self.set_active_context(active_context)
File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 250, in set_active_context
context_name)
File "/usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py", line 625, in get_with_name
'Expected object with name %s in %s list' % (name, self.name))
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. Expected object with name in /kubeconfig/contexts list
Shouldn’t the library assume ""
means the context is unset and avoid trying to look it up, or make the context
argument to config.load_kube_config()
mandatory?
Issue Analytics
- State:
- Created 3 years ago
- Comments:26 (9 by maintainers)
Top Results From Across the Web
Current context is not set Kubectl - Stack Overflow
The correct command is: kubectl config use-context ${CONTEXT}. You can confirm this with: kubectl config --help set-context Set a context ...
Read more >contextvars — Context Variables — Python 3.11.1 ...
This module provides APIs to manage, store, and access context-local state. The ContextVar class is used to declare and work with Context Variables....
Read more >Namespaces - Kubernetes
In Kubernetes, namespaces provides a mechanism for isolating groups of resources within a single cluster. Names of resources need to be unique ...
Read more >Install kubectl and configure cluster access - Google Cloud
Set a default cluster for kubectl by setting the current context in the kubeconfig file. Run kubectl commands against a specific cluster using...
Read more >Current-context must exist in order to minify - GitLab Forum
I've set up a kubernetes cluster on Google Cloud and have added Gitlab ... Any ideas what's causing the error error: current-context must ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am running into this issue just like @roycaihw is hitting. I am not able to list the context because the
current-context
is blank.If
current-context
is blank then it should still be possible to get a listing of the contexts.kubectl
supports this and doesn’t blow up.I can take that one. /assign