Finding the kubeconfig file being used Finding the kubeconfig file being used kubernetes kubernetes

Finding the kubeconfig file being used


Question: But is there a way to get the kubeconfig path/file details from the kubectl which one being currently used?

Yes, you can run any kubectl command with verbose level 6+ to see the kubeconfig in use.

kubectl get pod   -v6                                             I0629 04:48:25.050954   14444 loader.go:379] Config loaded from file:  /home/ps/.kube/configI0629 04:48:25.146072   14444 round_trippers.go:445] GET https://kubemaster:6443/api/v1/namespaces/default/pods?limit=500 200 OK in 10 millisecondsNo resources found in default namespace.

Few examples demonstrating the same:

kubectl get pod   -v6 2>&1 |awk  '/Config loaded from file:/{print $NF}'/home/ps/.kube/config

Changed thekubeconfig to /tmp/config

export KUBECONFIG=/tmp/config    kubectl get pod   -v6 2>&1 |awk  '/Config loaded from file:/{print $NF}'/tmp/config

Remove the awk command to see the whole output.

Windows output:

enter image description here