Tuesday, July 20, 2021

To switch between multiple kubernetes environments

 If you have a separate kubeconfig file you can switch between multiple kubernetes environments using


kubectl get pods --kubeconfig=c:\users\username\.kube\config.istio_azure -n testing3


Above will switch to kubernetes environment mentioned in config.istio_azure file and to namespace testing3


To switch between multiple kubernetes environments mentioned in the same config file use context option.


To see list of contexts available in the default config:

kubectl config get-contexts

Use --kubeconfig for a non-default config file

kubectl get pods --kubeconfig=c:\users\user1\.kube\config.istio_azure -n testing1

The default context will be added * in front of the output.

kubectl config get-clusters 

Also similar to get-contexts but without current context highlight.


Once we get the list of contexts available, you can run the commands using --context

kubectl get nodes --context kind-mycluster


Or you can switch the default cluster using:

kubectl config use-context kind-mycluster


To delete only from kubectl config file:

kubectl config delete-context istiok8s



No comments:

Post a Comment