kubeconfig (advanced)

Manage Kubernetes contexts and clusters in kubeconfig.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

kubectl uses kubeconfig (~/.kube/config) to store cluster credentials and contexts. A context pairs a cluster with credentials and a namespace. Managing multiple clusters requires switching contexts — and verifying you're in the right one before destructive operations.

Examples
kubectl config get-contextsList all available contexts · explain & risk-check →
kubectl config current-contextShow the active context · explain & risk-check →
kubectl config use-context prod-clusterSwitch to production cluster context · explain & risk-check →
kubectl config set-context --current --namespace=productionSet default namespace for current context · explain & risk-check →
KUBECONFIG=~/.kube/cluster1:~/.kube/cluster2 kubectl config view --merge --flatten > ~/.kube/configMerge multiple kubeconfig files · explain & risk-check →
Pro tip

Install kubectx and kubens (`brew install kubectx`) for fast context/namespace switching. Set a PS1 prompt that shows current context — catching wrong-cluster mistakes before they happen.

Related
kubectl get kubectl apply kubectl rollout
Open the full explainer →More in Kubernetes & Helm

Reference text is hand-written and may be incomplete — check man kubeconfig for your version. Test destructive commands on a non-production system first.