LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

kubectl-config

manage kubeconfig files: clusters, users, and contexts

TLDR

View the merged kubeconfig
$ kubectl config view
copy
View raw kubeconfig including secrets
$ kubectl config view --raw
copy
Show current context
$ kubectl config current-context
copy
List contexts
$ kubectl config get-contexts
copy
Switch context
$ kubectl config use-context [context-name]
copy
Set default namespace for the current context
$ kubectl config set-context --current --namespace=[namespace]
copy
Add a cluster entry
$ kubectl config set-cluster [name] --server=[https://api.example.com]
copy
Delete a context
$ kubectl config delete-context [context-name]
copy

SYNOPSIS

kubectl config SUBCOMMAND [options]

DESCRIPTION

kubectl config manages kubeconfig files, which store the connection details, credentials, and preferences needed to interact with Kubernetes clusters. A kubeconfig defines three list-shaped sections: clusters, users, and contexts, where each context binds a cluster, a user, and an optional default namespace.By default kubectl reads `~/.kube/config`. The loading order is the explicit --kubeconfig flag, then the colon-separated paths in the KUBECONFIG environment variable, then `~/.kube/config`. When KUBECONFIG lists multiple files, they are merged in order, with earlier files winning conflicts.The subcommands let you inspect the merged view, switch between contexts to target different clusters, set per-context defaults such as the namespace, and add or remove cluster, user and context entries.

PARAMETERS

view

Display the merged kubeconfig. Use --raw to include credentials, --minify to show only the current context, -o for a different output format.
current-context
Print the current-context.
use-context NAME
Set the current-context in the kubeconfig.
get-contexts [NAME]
List one or all contexts.
set-context NAME | --current
Create or modify a context. Use --current to update the active context (commonly with --namespace).
rename-context OLD NEW
Rename a context.
delete-context NAME
Remove a context.
get-clusters
List clusters defined in the kubeconfig.
set-cluster NAME [--server=URL] [--certificate-authority=FILE] [--insecure-skip-tls-verify]
Create or modify a cluster entry.
delete-cluster NAME
Remove a cluster entry.
get-users
List users defined in the kubeconfig.
set-credentials NAME [--token=BEARER] [--client-certificate=FILE] [--client-key=FILE] [--username=USER --password=PASS]
Create or modify a user entry.
delete-user NAME
Remove a user entry.
set PROPERTY VALUE
Set an individual value in the kubeconfig (dotted path).
unset PROPERTY
Unset an individual value.
--kubeconfig FILE
Operate on a specific kubeconfig file instead of the default chain.
--help
Display help information.

CAVEATS

kubectl config view redacts credentials by default; use --raw when you actually need the secret material (and handle the output carefully). kubectl config is a subcommand of kubectl: it edits the kubeconfig file, it does not talk to the cluster. For interactive context and namespace switching many users prefer kubectx and kubens.

HISTORY

kubectl config has shipped with kubectl since early Kubernetes releases and codifies the kubeconfig format used across the ecosystem (kubectl, client-go, Helm, kustomize, ...).

SEE ALSO

kubectl(1), kubectx(1), kubens(1)

Copied to clipboard
Kai