In Kubernetes, managing multiple environments—like development, staging, and production—requires a fast way to switch "where" your commands go. While many users look for a command literally called kubectl set current context , the actual operations are handled by the kubectl config suite of commands.
If you have a context named prod-cluster , switch to it by running: kubectl config use-context prod-cluster Use code with caution.
Before setting a context, you need to know the exact name of the context you wish to switch to. You can list all available contexts configured in your kubeconfig file by running: kubectl set current context
kubectl config use-context <context-name>
kubectl config set-context --current --namespace=development Use code with caution. Before setting a context, you need to know
kubectl config current-context
While many users intuitively try to type kubectl set current context , the actual command uses the config subcommand. To switch your active context, use the following syntax: To switch your active context, use the following
By mastering the use of Kubernetes contexts, you can efficiently manage and switch between different clusters and namespaces, enhancing your productivity when working with Kubernetes.