Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge kubectl config file with ~/.kube/config?

Tags:

kubernetes

Is there a simple kubectl command to take a kubeconfig file (that contains a cluster+context+user) and merge it into the ~/.kube/config file as an additional context?

like image 819
Chad Avatar asked Sep 12 '17 19:09

Chad


People also ask

How do I merge Kubeconfig files?

In the section "Merging kubeconfig files" below, we explain how you can merge the kubeconfigs into a single file, but you can also merge them in-memory. By specifying multiple files in KUBECONFIG environment variable, you can temporarily stitch kubeconfig files together and use them all in kubectl .


2 Answers

Do this:

export KUBECONFIG=~/.kube/config:~/someotherconfig  kubectl config view --flatten 

You can then pipe that out to a new file if needed.

like image 193
jaxxstorm Avatar answered Sep 18 '22 22:09

jaxxstorm


If you find yourself doing this a lot... There is now also the krew plugin package manager for kubectl.

The krew plugin "konfig" can help you manage your ~/.kube/config file.

Using the konfig plugin the syntax will be:

kubectl konfig import -s new.yaml

To install krew: https://github.com/kubernetes-sigs/krew

To install konfig: kubectl krew install konfig

like image 38
dhr_p Avatar answered Sep 18 '22 22:09

dhr_p