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?
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 .
Do this:
export KUBECONFIG=~/.kube/config:~/someotherconfig kubectl config view --flatten
You can then pipe that out to a new file if needed.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With