kubectl-config
Configure access to Kubernetes clusters
TLDR
Get all contexts in the default kubeconfig file
Get all clusters/contexts/users in a custom kubeconfig file
Get the current context
Set the default namespace of the current context
Switch to another context
Delete clusters/contexts/users
Permanently add custom kubeconfig files
SYNOPSIS
kubectl config <SUBCOMMAND> [flags]
PARAMETERS
current-context
Displays the current context
delete-cluster NAME
Delete named cluster from kubeconfig
delete-context NAME
Delete named context from kubeconfig
delete-user NAME
Delete named user (auth-info alias) from kubeconfig
get-clusters
Display list of defined clusters
get-contexts
Describe one or all contexts
rename-context OLD NEW
Renames a context
set
Sets an individual value in kubeconfig (alias for set-cluster etc.)
set-cluster NAME [--server=url] [--certificate-authority=path]
Sets a cluster entry in kubeconfig
set-context NAME [--cluster=NAME] [--user=NAME] [--namespace=NS]
Sets a context entry in kubeconfig
set-credentials NAME [--client-certificate=path]
Sets a user entry in kubeconfig
unset PROPERTY
Unsets a property in kubeconfig (e.g., current-context)
use-context NAME
Sets the current context
view [--minify] [--flatten]
Display merged kubeconfig settings or specified file
--kubeconfig string
Use a particular kubeconfig file
--help -h
Help for config
DESCRIPTION
kubectl config manages the kubeconfig file used by kubectl to store cluster, user, and context configurations for accessing Kubernetes clusters.
A kubeconfig file defines clusters (with server URLs and certificates), users (credentials like tokens or certs), and contexts (combinations of cluster, user, and namespace). This command enables viewing, editing, and switching these settings without manually editing YAML files.
Key operations include listing contexts, switching the active context, adding new clusters or credentials, and unsetting values. It supports multiple kubeconfig files via the KUBECONFIG environment variable, merging them hierarchically (last file wins conflicts).
Default file is $HOME/.kube/config. Ideal for multi-cluster setups, CI/CD pipelines, and troubleshooting access issues. Always verify changes with kubectl config view to avoid disrupting access.
CAVEATS
Modifies kubeconfig in place; backup before changes. Multiple files merged via KUBECONFIG (last overrides). Some subcommands fail if values missing.
DEFAULT KUBECONFIG
$HOME/.kube/config; created on first kubectl use.
KUBECONFIG ENV
Colon-separated list of files to merge for requests.
HISTORY
Introduced in early Kubernetes releases (~v1.2, 2015) as part of kubectl; evolved with multi-cluster support in v1.14+ and OpenID Connect integration.
SEE ALSO
kubectl(1)


