Set-context — Kubectl
# 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 --current --namespace=backend Output: 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. # Good: Relies on context namespace kubectl get
The command kubectl set-context allows you to create or modify these profiles without ever touching a YAML file. The basic syntax is: This is the most common real-world use case
kubectl get ns # Output shows resources in default namespace (or whatever is set) To change the default namespace for your current context to backend :