Skip to content

Instantly share code, notes, and snippets.

@asabirov
Last active February 17, 2021 05:44
Show Gist options
  • Save asabirov/8869de35f577b95f22788fecf1ac1754 to your computer and use it in GitHub Desktop.
Save asabirov/8869de35f577b95f22788fecf1ac1754 to your computer and use it in GitHub Desktop.
Use multiple kube config files for kubectl
#!/usr/bin/env bash
DEFAULT_KUBECONFIG_FILE="$HOME/.kube/config"
if test -f "${DEFAULT_KUBECONFIG_FILE}"
then
export KUBECONFIG="$DEFAULT_KUBECONFIG_FILE"
fi
# Your additional kubeconfig files should be inside ~/.kube/configs
ADD_KUBECONFIG_FILES="$HOME/.kube/configs"
mkdir -p "${ADD_KUBECONFIG_FILES}"
OIFS="$IFS"
IFS=$'\n'
for kubeconfigFile in `find "${ADD_KUBECONFIG_FILES}" -type f -name "*.yml" -o -name "*.yaml"`
do
export KUBECONFIG="$kubeconfigFile:$KUBECONFIG"
done
IFS="$OIFS"
@asabirov
Copy link
Author

source ./load-configs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment