Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Issue with Merging Kubernetes Kubeconfig Files

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:

  1. How can I ensure correct user attributes when switching contexts?
  2. Any tips to validate debug the merged kubeconfig?

Any insights would be appreciated.





Solved Solved
0 1 167
1 ACCEPTED SOLUTION

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".

 

View solution in original post

1 REPLY 1

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".