By default, kubectl
configuration is located at ~/.kube/config
. Is it possible to specify the kubeconfig file explicitly when using the kubectl
command?
Asked
Active
Viewed 4,819 times
2

stackprotector
- 10,498
- 4
- 35
- 64

zjffdu
- 25,496
- 45
- 109
- 159
3 Answers
8
kubectl
can use the KUBECONFIG
in three different ways:
Using the
KUBECONFIG
present in~/.kube/config
if nothing is specified inkubectl
command.Using the
KUBECONFIG
defined by using theKUBECONFIG
environment variable if nothing is specified inkubectl
command.Passing the
KUBECONFIG
as part of thekubectl
command using the--kubeconfig
flag as:kubectl --kubeconfig=<KUBECONFIG_PATH>
Further, the order of precedence is as follows:
- Use the
KUBECONFIG
if explicitly passed in thekubectl
command - Use the
KUBECONFIG
from the environment variable if--kubeconfig
flag is not specified but the environment variable is set. - Use the
KUBECONFIG
from~/.kube/config
if both--kubeconfig
andKUBECONFIG
are not specified.

Krishna Chaurasia
- 8,924
- 6
- 22
- 35
3
Use KUBECONFIG
env for using custom kubeconfig file with kubectl
:
$ export KUBECONFIG=/path/to/config

Kamol Hasan
- 12,218
- 1
- 37
- 46
2
Yes you can specify like this
kubectl config --kubeconfig=your_kubeconfi_file_path <YOUR_OPERATION>

Dashrath Mundkar
- 7,956
- 2
- 28
- 42