kubectl: Get location of KubeConfig file in use

Viewed 24385

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
1 Answers

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.

Related