Kubectl List Contexts Jun 2026

: If you only need a list of context names (useful for scripts), use: kubectl config get-contexts -o name

CURRENT NAME CLUSTER AUTHINFO NAMESPACE * dev dev-cluster dev-user development staging stg-cluster stg-user staging prod prod-cluster prod-user production kubectl list contexts

for ctx in $(kubectl config get-contexts -o name); do ns=$(kubectl config view --context=$ctx --minify -o jsonpath='..namespace') echo "$ctx → namespace: $ns:-default" done : If you only need a list of

| Command | Purpose | | :--- | :--- | | kubectl config get-contexts | List all contexts available. | | kubectl config current-context | Show the name of the currently active context. | | kubectl config use-context <name> | Switch the active context to <name> . | | kubectl config get-contexts -o json | List contexts in machine-readable JSON format. | | | kubectl config get-contexts -o json |