konfig helps to merge, split or import kubeconfig files
The following assumes that you have installed konfig via
kubectl krew install konfigkubectl konfig import --save new-cfgImports the config file new-cfg into the default kubeconfig at ~/.kube/config.
To show the result without changing your kubeconfig, do
kubectl konfig import new-cfgCAVEAT: due to how shells work, the following will lose your current ~/.kube/config
# WRONG, don't do this!
kubectl konfig import new-cfg > ~/.kube/configkubectl konfig merge config1 config2 > merged-configThis variant creates a self-contained kubeconfig where all credentials are stored inline in the kubeconfig.
If you want to preserve the structure and keep credentials separate, use --preserve-structure.
This will extract a minimal kubeconfig with a single context minikube:
# extract context minikube from the default kubeconfig
kubectl konfig export minikube > minikube.config
# extract context minikube and docker-for-desktop from two input configs
kubectl konfig export minikube docker-for-desktop -k ~/.kube/other,~/dockercfg > local