Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save generated kube config to .kube/config

I'm using rke to generate a Kubernetes cluster in a private cloud. It produces a kube_config_cluster.yml file. Is there a way to add this config to my $HOME/.kube/config file?

Without having the .kube/config set, when using kubectl, I have to pass the argument:

kubectl --kubeconfig kube_config_cluster.yml <command>

Or set the KUBECONFIG environment variable.

export KUBECONFIG=kube_config_cluster.yml
like image 657
Highway of Life Avatar asked Mar 09 '18 22:03

Highway of Life


2 Answers

kubectl config merge command is not yet available. But you can achieve a config merge by running:

Command format:

KUBECONFIG=config1:config2 kubectl config view --flatten

Example:

Merge a config to ~/.kube/config and write back to ~/.kube/config-new.yaml.

Do not pipe directly to the config file! Otherwise, it will delete all your old content!

KUBECONFIG=~/.kube/config:/path/to/another/config.yml kubectl config view --flatten > ~/.kube/config-new.yaml

cp ~/.kube/config-new.yaml ~/.kube/config

like image 106
Highway of Life Avatar answered Nov 15 '22 09:11

Highway of Life


If kubectl can read that as a valid config file, you can just use that as your kubeconfig. So cp kube_config_cluster.yaml $HOME/.kube/config should work fine. From there it'll read that config file by default and you won't have to specify it.

like image 35
Grant David Bachman Avatar answered Nov 15 '22 08:11

Grant David Bachman