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
kubectl cluster-info
Prints the endpoints of the control-plane services for the current context. The dump subcommand collects a large diagnostic bundle of cluster state for offline analysis.
kubectl get
Lists one or more resources of a given type from the cluster. It is the primary read command for pods, services, deployments, and any other Kubernetes object, with flexible output formats for scripting and inspection.
kubectl explain
Prints documentation for a resource kind and its fields, sourced from the live cluster's OpenAPI schema. It is the offline-safe reference for authoring manifests against the exact API version your cluster serves.