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

CommandWhat it does
kubectl config get-contextsList clusters, users, namespaces
kubectl config use-context prodSwitch active cluster
kubectl config set-context --current --namespace=shopDefault namespace for this context
kubectl cluster-infoControl-plane endpoints
KUBECONFIG=~/.kube/prod.yaml kubectl get nodesOne-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.

자주 묻는 질문

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.

Kubernetes