To make your payment please select the location below where your procedure was performed. After clicking you will be redirected to the ePay website to securely complete your payment.
Capitola Cass Munras Ryan Ranch Salinaskuse prod-us-east k get pods # Now uses production context Add to ~/.bashrc :
# Switch to development context kubectl config use-context dev-europe kubectl config use-context staging-asia kubectl use context
This guide should help you effectively manage multiple Kubernetes clusters and environments using kubectl contexts . kuse prod-us-east k get pods # Now uses
# Always check current context before delete operations echo "Current context: $(kubectl config current-context)" kubectl delete deployment important-app | Command | Purpose | |---------|---------| | kubectl config get-contexts | List all contexts | | kubectl config current-context | Show active context | | kubectl config use-context <name> | Switch context | | kubectl config set-context <name> ... | Create context | | kubectl config delete-context <name> | Remove context | | kubectl --context=<name> <command> | One-off context use | | kubectl config set-context --current --namespace=<ns> | Change default namespace | Create a new context # Basic syntax kubectl
After switching, all subsequent kubectl commands will use the new context. Create a new context # Basic syntax kubectl config set-context <context-name> \ --cluster=<cluster-name> \ --user=<user-name> \ --namespace=<namespace> Example:
kubectl config set-context my-prod-context \ --cluster=production-cluster \ --user=admin \ --namespace=default # Rename by creating a new one and deleting the old kubectl config set-context new-name --cluster=old-cluster --user=old-user kubectl config delete-context old-name Delete a context kubectl config delete-context <context-name> Advanced Tips Temporary context switch (without changing default) # Use a different context for a single command kubectl --context=staging-asia get pods Multiple commands with temporary context kubectl --context=dev-europe get nodes kubectl --context=dev-europe get services Set default namespace for a context # Modify existing context kubectl config set-context --current --namespace=<namespace> Or specify context explicitly kubectl config set-context dev-europe --namespace=frontend Use aliases for efficiency Add to ~/.bashrc or ~/.zshrc :