I’ve merged two kubeconfig files using:
export KUBECONFIG config-demo:config-demo-2
The contexts appear correctly with kubectl config view, but when switching to dev-ramp-up using:
kubectl config use-context dev-ramp-up
The error I’m getting is
Error from server (Unauthorized): the server does not allow this request for this user on the current namespace.
Running kubectl auth whoami shows incorrect/missing user attributes.
Questions:
- How can I ensure correct user attributes when switching contexts?
- Any tips to validate debug the merged kubeconfig?
Any insights would be appreciated.
I would highly recommend kubectx to solve this issue, thats best suited for this issue.
# switch to another cluster that's in kubeconfig
$ kubectx minikube
Switched to context "minikube".
# switch back to previous cluster
$ kubectx -
Switched to context "oregon".
# rename context
$ kubectx dublin=gke_ahmetb_europe-west1-b_dublin
Context "gke_ahmetb_europe-west1-b_dublin" renamed to "dublin".
# change the active namespace on kubectl
$ kubens kube-system
Context "test" set.
Active namespace is "kube-system".
# go back to the previous namespace
$ kubens -
Context "test" set.
Active namespace is "default".
# change the active namespace even if it doesn't exist
$ kubens not-found-namespace --force
Context "test" set.
Active namespace is "not-found-namespace".
---
$ kubens not-found-namespace -f
Context "test" set.
Active namespace is "not-found-namespace".
2 Likes