Use kubeconfig files to organize information about clusters, users, namespaces, and authentication mechanisms. The kubectl
command uses kubeconfig files to find the information it needs to choose a cluster and communicate with the API server of a cluster.
By default, kubectl
looks for a file named config
in the $HOME/.kube
directory. You can specify other kubeconfig files by setting the KUBECONFIG
environment variable or by setting the —kubeconfig
flag.
Suppose you have several clusters, and your users and components authenticate in a variety of ways. For example:
With kubeconfig files, you can organize your clusters, users, and namespaces. You can also define contexts to quickly and easily switch between clusters and namespaces.
A context element in a kubeconfig file is used to group access parameters under a convenient name. Each context has three parameters: cluster, namespace, and user. By default, the kubectl
uses parameters from the current-context
to communicate with the cluster.
To choose the current context:
kubectl config use-context ${context}
The KUBECONFIG
environment variable holds a list of kubeconfig files. For Linux and Mac, the list is colon-delimited. For Windows, the list is semicolon-delimited. The KUBECONFIG
environment variable is not required. If the KUBECONFIG
doesn't exist, kubectl
uses the default kubeconfig file ($HOME/.kube/config
).