k8s-inventory icon indicating copy to clipboard operation
k8s-inventory copied to clipboard

Automatically use KUBECONFIG env var

Open AdrianoKF opened this issue 3 years ago • 3 comments

What would you like to be added:

Currently, kai will use ~/.kube/config to connect to the cluster, even if the KUBECONFIG environment variable points to a different file. This makes it necessary to manually specify the -k $KUBECONFIG option when calling kai, creating the risk of inadvertently running kai against a different cluster than kubectl.

I would propose that kai should automatically use the kubeconfig file pointed to by the KUBECONFIG enviroment variable if it is set, otherwise attempt to use the current default of ~/.kube/config as a fallback to be consistent with other k8s tools.

Why is this needed:

Some users keep multiple separate kubeconfig files and switch between them by pointing the KUBECONFIG environment variable at the active config file. Kubectl and friends automatically pick up the active config from the environment, so having kai do the same would increase consistency and reduce the surprise factor for the user.

Additional context:

AdrianoKF avatar Jul 27 '21 06:07 AdrianoKF

Hello @AdrianoKF! Thanks for submitting the request. I have passed it along to PM for review

zburstein avatar Aug 24 '21 19:08 zburstein

@AdrianoKF @zburstein just wanna check on something real quick here!

The environment variable to set the kubeconfig path should take precedence, but want to make sure we're setting the right one. In order for KAI to prefer a different path besides the home directory's kubeconfig, it looks in the following places:

  1. KAI_KUBECONFIG_PATH
  2. kai.yaml kubeconfig path override: kubeconfig.path
  3. kai.yaml direct kube config (i.e. translating the actual kubeconfig into the kai.yaml file)
  4. ~.kube/config

So, as you mentioned, kai is not respecting the KUBECONFIG env var directly, but it would respect KAI_KUBECONFIG_PATH. It seems that you're suggesting that the KUBECONFIG env var is used more commonly by k8s operators and that we should interpret that as well. Perhaps we could add it between options 3 and 4 above in terms of order of precedence? Would that satisfy the feature request as it's laid out in your comment?

dakaneye avatar Sep 01 '21 13:09 dakaneye

@dakaneye Yes, I like adding it between 3 and 4. That'll allow for it to work as expected.

flickerfly avatar Sep 06 '22 18:09 flickerfly