In the past, I used $HOME/.kube/config
and downloaded the kubeconfig file from Rancher.
There was only one kubeconfig file (see docs) so I never wondered about which file was being used.
Yesterday, I switched to using the KUBECONFIG environment variable because there are several k8s clusters I'm now using (prod, stg, dev), and that's what the devops team told me to do, so I did it (and it worked). For the sake of discussion, the command was:
export KUBECONFIG=$HOME/.kube/config-prod:$HOME/.kube/config-stage:$HOME/.kube/config-dev
So now I can use following commands to use the staging K8S cluster.
kubectl config current-context
# verify I'm in the using the right k8s config, and switch if necessary
kubectl config use-context dev <<< WHERE DOES kubectl store this setting???
kubectl config set-context --current --namespace MyDeploymentNamespace
kubectl get pods
My question is How does does kubectl know what kube config file is being used? Where does it store the currently selected context?
or instead
Does kubectl logically concatenate all of the kubeconfig files defined in the KUBECONFIG environment variable to get access to any of the defined Kubernetes clusters?
Searching for answer
I found several answers to similar questions but not quite this question.
- kubectl: Get location of KubeConfig file in use is similar and points to Finding the kubeconfig file being used
Which explains how to the file
kubectl config current-context -v6
I0203 14:59:05.926287 30654 loader.go:375] Config loaded from file: /home/user1/.kube/config
dev
I'm asking where is this information stored?
The only guess I have is in the $HOME/.kube/cache directory in which I'm finding scores of files.
Some Kubernetes documentation