Skip to content

Instantly share code, notes, and snippets.

@dgacias
Created September 2, 2025 10:06
Show Gist options
  • Select an option

  • Save dgacias/e31b866d629f3058a79792ae3134cb29 to your computer and use it in GitHub Desktop.

Select an option

Save dgacias/e31b866d629f3058a79792ae3134cb29 to your computer and use it in GitHub Desktop.
Merge kubeconfig function for bash
#Add this function to your .bashrc file.
kube-merge() {
local files=(~/.kube/config ~/.kube/*.yml)
KUBECONFIG=$(IFS=:; echo "${files[*]}") kubectl config view --merge --flatten > ~/.kube/config
unset KUBECONFIG
echo "Kubeconfigs merged in ~/.kube/config"
echo "KUBECONFIG var has been unset"
echo "You can list your current contexts with: $ kubectl config get-contexts"
}
#Relog your session or execute this command: $ source ~/.bashrc
#Then you can execute $ kube-merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment