Last active
February 22, 2025 10:50
-
-
Save MParvin/d5aabccc7a53bf20f8730abf35e240e3 to your computer and use it in GitHub Desktop.
Merge kubeernetes cube config files into a single file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
show_usage() { | |
echo "Usage: $0 <config1> <config2> ..." | |
echo "This script will merge config1, config2, ... into a single config file in current directory" | |
echo "The merged config file will be named as 'merged-kubeconfig'" | |
echo "You can copy the merged config file to ~/kube/config to use it as your default kubeconfig" | |
} | |
if [ $# -lt 2 ]; then | |
show_usage | |
exit 1 | |
fi | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
show_usage | |
exit 0 | |
fi | |
kube_config_files="" | |
for i in "$@" | |
do | |
kube_config_files="$kube_config_files:$i" | |
done | |
# remove the first colon | |
kube_config_files=${kube_config_files:1} | |
# merge the kube config files | |
KUBECONFIG=$kube_config_files kubectl config view --flatten > merged-kubeconfig | |
echo "Merged kube config files: $kube_config_files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment