Description
When using a config with multiple contexts, one might see a surprising message if there is no context set.
Let me demostrate:
$ k config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
coldsweet microk8s-cluster admin-microk8s coldsweet
devops devops-calico admin
devops-cilium devops-cilium admin-cilium
* microk8s-context microk8s-cluster admin-microk8s
Here, I have a context set. So kubectl get pods
or any other command works fine.
If there is no current-context, kubectl says it can't connect to localhost (that's reasonable if you know k8s, more on that below).
sed -i '/current-context/d' ~/.kube/config
$ k config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
coldsweet microk8s-cluster admin-microk8s coldsweet
devops devops-calico admin
devops-cilium devops-cilium admin-cilium
microk8s-context microk8s-cluster admin-microk8s
$ k get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
What would you like to be added:
The above message is baffling if you encounter this for the first time. A better message would be something like this:
Mutliple contexts found but no context is set. Which cluster shall I use? Please set an active context
Why is this needed:
I give Kubernetes workshops, where students use multiple clusters. As we go through setting ~/.kube/confing
for usage with multiple clusters, some students will rush to try stuff, and forget to set a context. This results in frustration and funny facial expressions staring at the screen. We explain that kubectl
, uses localhost per default - and that older versions of kubernetes where not secured on localhost. A much better UI will be simply telling the user he didn't set up a context.
I'm willing to send a PR for improving this UI. This should not be hard to fix (I have already submitted code to k8s/k8s).
/sig usability