Kubernetes Commands: kubectl config – kubernetes kube config file – Tutorials and Examples

The kubectl command-line tool uses kubeconfig files(file named with – config) to find the information it needs to choose a cluster and communicate with the API server of a cluster.

Note:
A file that is used to configure access to clusters is called a kubeconfig file. This is a generic way of referring to configuration files. It does not mean that there is a file named kubeconfig.

How to set kubeconfig file to kubectl?

  • Method 1 – By default, kubectl looks for a file named config in the $HOME/.kube directory.
  • Method 2 – You can specify other kubeconfig files by setting the KUBECONFIG environment variable or
  • Method 3 – You can specify other kubeconfig files by setting the –kubeconfig flag.

The loading order follows these rules:

  • Rules 1 – If the –kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.
  • Rules 2 – If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list.
  • Rules 3 – Otherwise, ${HOME}/.kube/config is used and no merging takes place.

Skeleton/Example of kube config file

Rajesh Kumar
Total Page Visits: 23 - Today Page Visits: 1