Kubectl Set-context — _hot_

kubectl set-context development --namespace=testing Need to repoint a context to a different cluster? You can do that without deleting and recreating it.

cat ~/.kube/config A context entry in the file looks like this: kubectl set-context

kubectl set-context production --cluster=aws-prod --user=admin-user This creates the context but does not switch to it. To switch, you would run kubectl use-context production . This is the most common real-world use case. You have a context called staging , but you are tired of typing -n backend for every command. To switch, you would run kubectl use-context production

kubectl set-context --current --namespace=backend Output: kubectl set-context

kubectl get ns # Output shows resources in default namespace (or whatever is set) To change the default namespace for your current context to backend :

kubectl set-context development --cluster=staging-cluster This updates the development context to use staging-cluster instead of its original cluster. kubectl set-context modifies your kubeconfig file (usually ~/.kube/config ). You can see the changes directly:

# Good: Relies on context namespace kubectl get pods kubectl get pods -n default 3. Verify Before You Execute Create a shell alias to show your current context in your prompt: