kubectl: Get location of KubeConfig file in use [closed]
Asked Answered
C

1

20

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
Chalet answered 14/10, 2020 at 3:21 Comment(2)
#68173143Bonaventura
Similar question: #75338132Lieabed
C
21

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.

Camire answered 14/10, 2020 at 4:43 Comment(4)
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.Chalet
How would you know which kubeconfig is in use when your KUBECONFIG environment variable contains multiple files?Chalet
Hi @RohanKumar while scouring documentation i found this - "If KUBECONFIG contains multiple paths, the first one is used." cloud.google.com/sdk/gcloud/reference/container/clusters/…Hortatory
#68173143Mim

© 2022 - 2024 — McMap. All rights reserved.