kubectl 1.37 reference · Access and Configuration

kubectl config Command (kubectl)

Inspect and switch kubeconfig contexts (cluster, user and default namespace), and set the namespace for the current context.

kubectl 1.37

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

kubectl config get-contexts | current-context | use-context NAME | set-context --current --namespace=NS

Parameters

ParameterDescription
get-contexts List contexts.
use-context NAME Switch cluster/user.
set-context --current --namespace=NS Change the default namespace.

Examples

Which cluster am I talking to?
kubectl config current-context
kubectl config get-contexts -o name

Output

kind-rc-docs
kind-rc-docs

Run this on your computer — see “Get Started” for setup.

The current context's cluster and user
kubectl config view --minify -o jsonpath='cluster: {.clusters[0].name}, user: {.users[0].name}{"\n"}'

Output

cluster: kind-rc-docs, user: kind-rc-docs

Run this on your computer — see “Get Started” for setup.

Many accidents are commands run against the wrong cluster: show the context in your shell prompt and use separate kubeconfig files for production.

Was this page helpful?