WHAT TO EXPECT
In this article, users will learn how to change the working context in a Kubernetes environment to use a different default.
To Change K8s Context in Your Preferred Cloud
If there is more than one K8s cluster in your preferred cloud, then you may need to switch between them to run commands in the CloudShell Bash. Below are the steps to switch between K8s clusters.
Get a list of all K8s Contexts by using the following command:
kubectl config get-contextsExample in Azure:
$ kubectl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE cilium-sample cilium-sample clusterUser_saDevNetwork_cilium-sample cilium-sample-200 cilium-sample-200 clusterUser_test-donna-200-rg_cilium-sample-200 cilium-sample2 cilium-sample2 clusterUser_saDevNetwork_cilium-sample2 * cilium-sample300 cilium-sample300 clusterUser_test-donna-300-rg_cilium-sample300 dsd-k8-cluster-100 dsd-k8-cluster-100 clusterUser_saDevNetwork_dsd-k8-cluster-100Notice in the above list, there are multiple contexts, but only one has the asterisks (*). The asterisks mark the default context.
To change context, run the following command. The example is changing to cilium-sample2.
kubectl config use-context cilium-sample2Re-run the get-context command:
kubectl config get-contextsExample in Azure:
$ kubectl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE cilium-sample cilium-sample clusterUser_saDevNetwork_cilium-sample cilium-sample-200 cilium-sample-200 clusterUser_test-donna-200-rg_cilium-sample-200 * cilium-sample2 cilium-sample2 clusterUser_saDevNetwork_cilium-sample2 cilium-sample300 cilium-sample300 clusterUser_test-donna-300-rg_cilium-sample300 dsd-k8-cluster-100 dsd-k8-cluster-100 clusterUser_saDevNetwork_dsd-k8-cluster-100As you can see above, the asterisk (*) has changed positions to the desired context, cilium-sample2.