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 --namespace=testing Need to repoint a context to a different cluster? You can do that without deleting and recreating it. kubectl set-context
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: kubectl get ns # Output shows resources in
# 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: kubectl set-context is deceptively simple
export KUBECONFIG=~/.kube/config:~/secrets/gke-config kubectl set-context gke-prod --cluster=gke-prod --user=gke-user The command will update the first writable file in the list (usually the first one). kubectl set-context is deceptively simple. It does one small thing—modifying a field in a text file—but that small thing is the foundation of safe, efficient multi-cluster Kubernetes administration.
Check your current namespace:
Context "staging" modified. Now, any kubectl get pods will automatically show pods in the backend namespace. This is non-destructive; you can always override it with -n frontend when needed. You don't have to be using a context to modify it. To change the default namespace for the development context (even if you are currently in production ):