Kubectl — Set-context [updated]
The kubectl set-context command simply manipulates these fields. Understanding this is empowering—you can now safely script context changes or manually edit the file for advanced scenarios.
Let's break down each flag:
kubectl set-context --current --namespace=backend kubectl set-context
# Create a new context linking a specific user to a specific cluster kubectl config set-context new-exp-context --cluster=exp-cluster --user=exp-user kubectl set-context
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. kubectl set-context
Output:
Verification: Always follow a set-context command with kubectl config get-contexts to verify your changes were saved correctly (Spacelift).