18

When I'm using kubectl on top of Kubernetes. I can view contents of KUBECONFIG file like this:

$ kubectl config view

Is there any way I can find out which I can find out the location of KUBECONFIG file kubectl is using? I'm looking for something like:

$ kubectl config get-location
/path/to/kube-config/file
Rohan Kumar
  • 5,427
  • 8
  • 25
  • 40
  • 4
    https://stackoverflow.com/questions/68172643/finding-the-kubeconfig-file-being-used/68172779#68172779 – P.... Jun 29 '21 at 05:27
  • Similar question: https://stackoverflow.com/questions/75337632/how-does-kubectl-know-which-kubeconfig-config-file-to-use – PatS Feb 10 '23 at 14:29

1 Answers1

18

The kubeconfig directory is default to $HOME/.kube/config. But it can be overwritten by $KUBECONFIG env.

To get your kubeconfig directory, run:

$ [[ ! -z "$KUBECONFIG" ]] && echo "$KUBECONFIG" || echo "$HOME/.kube/config"

What it does? If $KUBECONFIG is set, print the value. Otherwise, print the default value.

Community
  • 1
  • 1
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • 1
    Thanks for your response. Yes, I'm aware of `KUBECONFIG` environment variable but I was looking if there is an option supported in `kubectl` to print which kubeconfig file is it loading. – Rohan Kumar Oct 14 '20 at 09:34
  • 1
    How would you know which `kubeconfig` is in use when your `KUBECONFIG` environment variable contains multiple files? – Rohan Kumar Oct 14 '20 at 09:38
  • Hi @RohanKumar while scouring documentation i found this - "If KUBECONFIG contains multiple paths, the first one is used." https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials – mc_lean May 24 '21 at 15:51
  • https://stackoverflow.com/questions/68172643/finding-the-kubeconfig-file-being-used/68172779#68172779 – Logu Jun 29 '21 at 05:24