config

kubectl config

Reads and modifies kubeconfig files that define clusters, users, and contexts. It is how you switch between clusters, change the active namespace, and register new credentials.

kubectl config SUBCOMMAND (view|get-contexts|use-context|set-context|current-context|set-credentials|set-cluster) [flags]

Common flags

Flag Purpose
--kubeconfig Override the config file path (default $KUBECONFIG or ~/.kube/config).
--minify With view, keep only entries used by the current context.
--flatten Inline referenced cert/token files into the output.
--current For set-context, edit the currently-selected context.
-o, --output Format for view/get-contexts (yaml, json, name).

Examples

kubectl config get-contexts

List every context in your kubeconfig.

kubectl config use-context prod-cluster

Switch the active context.

kubectl config set-context --current --namespace=team-a

Pin the current context to a namespace.

kubectl config view --minify --flatten -o yaml

Export a self-contained kubeconfig for the active context.

Gotcha

$KUBECONFIG can be a colon-separated (semicolon on Windows) list; edits go to the first file unless you pass --kubeconfig. use-context does not validate that the cluster is reachable.

Related commands

← All kubectl commands · Docker vs Kubernetes