
Merge Kube Config in PowerShell
Merging Kubernetes Config files is a rather cumbersome process. You can manually copy in the values but sometimes that doesn’t always go as planned. I was looking for a way to merge Kube Config files when I ran across a great post that wasn’t geared for PowerShell users.
Key Takeaways
- Must use full path. Relative paths did not work.
- $ENV:KUBECONFIG was an empty value before I set it.
- –flatten – is used to flatten the kubeconfig file into a self-contained output.
For this demo, my newly created Kubernetes Config file will be called config-devbox
.
I have to thank Jacob Tomlinson for his post on Medium “How to merge Kubernetes kubectl config files”, however, his post was not based on Windows PowerShell users. If you’re looking for the Bash equivalent I suggest you visit his post!
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# make a backup cd ~/.kube/ cp config config.bak # merge both kube config files $ENV:KUBECONFIG = "C:\Users\mrjamiebowman\.kube\config;C:\Users\mrjamiebowman\.kube\config-devbox" # verify that the variable is set $ENV:KUBECONFIG # output to temp file kubectl config view --flatten > config-merged # verify that config-merged is correct kubectl --kubeconfig=config-merged config get-clusters # delete backup rm config # move merged file to config mv config-merged config # remove (optional) rm config.bak |
Clean Up
To remove old clusters by name see the commands below.
1 2 3 4 5 |
# list all clusters kubectl config get-clusters # delete cluster by name kubectl config delete-cluster minikube |
Further Reading
https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands