kubectl Contexts commands

21 commands in 3 groups: Manage Contexts, Clusters & Credentials, List & Inspect. Click or tap any command to copy it. Official documentation: kubernetes.io.

Open in the interactive cheat sheet search, stars and every other section

Manage Contexts

Create, update, rename, switch, and delete contexts in kubeconfig.
kubectl config delete-context <name>
Delete a context
kubectl config rename-context <old> <new>
Rename a context
kubectl config unset contexts.<name>
Remove a context entry from kubeconfig
kubectl config use-context <name>
Switch to a different context
kubectl config set-context --current --cluster=<name>
Change cluster for current context
kubectl config set-context --current --namespace=<ns>
Set default namespace for current context
kubectl config set-context <name> --cluster=<cluster> --user=<user> --namespace=<ns>
Create or update a context

Clusters & Credentials

Add, update, and remove cluster endpoints and user credentials in kubeconfig.
kubectl config delete-cluster <name>
Remove a cluster from kubeconfig
kubectl config delete-user <name>
Remove a user from kubeconfig
kubectl config set-cluster <name> --insecure-skip-tls-verify=true
Disable TLS verification for cluster
kubectl config set-cluster <name> --server=<url>
Add or update a cluster endpoint
kubectl config set-credentials <name> --token=<token>
Add token-based user credentials
kubectl config set-credentials <name> --client-certificate=<cert> --client-key=<key>
Add certificate-based credentials

List & Inspect

Inspect kubeconfig, list available contexts, clusters, and users.
kubectl config current-context
Show active context
kubectl config get-clusters
List all clusters in kubeconfig
kubectl config get-contexts
List all kubeconfig contexts
kubectl config get-users
List all users in kubeconfig
kubectl config view
View full kubeconfig
kubectl config view --flatten
Self-contained kubeconfig with certs and tokens inlined (contains secrets)
kubectl config view --minify
View current context config only
kubectl config view --raw
Full kubeconfig including credentials (for backup/migration)