Saturday 9 July 2022

Listing and Switching Kubernetes Config Contexts

You may be having to work with multiple Kubernetes clusters while development or administering. Once you add credentials to kubeconfig you can work with a single cluster at a time, sing kubectl commands. In this post let's see how we can list and switch between different Kubernetes clsuters added to kubeconfig.

To list all the clusters available for you in kubeconfig you can execute the below command. To add a AKS cluster to your kubeconfig you can use instrcutions here.

kubectl config get-contexts


You can see three clusters available, two AKS clusters and one Kubernetes cluster created with K3D locally. The currently active context in the config is marked with an asterisk. If you list the namespaces available in the cluster you can see the namespaces from the curretly selected cluster.

To switch context to another cluster you can use the command below

kubectl config use-context contextName

Once sitched the context subsequent commands will be executed against the newly selected cluster.



No comments:

Popular Posts