Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
- kubectl context
- kubeconfig
- switch cluster
- kubectl namespace
- cluster-info
Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
Commands
| Command | What it does |
|---|---|
kubectl config get-contexts | List clusters, users, namespaces |
kubectl config use-context prod | Switch active cluster |
kubectl config set-context --current --namespace=shop | Default namespace for this context |
kubectl cluster-info | Control-plane endpoints |
KUBECONFIG=~/.kube/prod.yaml kubectl get nodes | One-off kubeconfig without switching |
Example
kubectl config get-contexts
kubectl config use-context staging
kubectl config set-context --current --namespace=shop
FAQ
How do I avoid running prod commands by accident?
Name contexts clearly (prod-*) and set per-context namespaces; use kubectx/kubens or a colored prompt.
Where is kubeconfig stored?
Default ~/.kube/config; KUBECONFIG env can stack multiple files with : separators.
Câu hỏi thường gặp
How do I avoid running prod commands by accident?
Name contexts clearly (prod-*) and set per-context namespaces; use kubectx/kubens or a colored prompt.
Where is kubeconfig stored?
Default ~/.kube/config; KUBECONFIG env can stack multiple files with : separators.