Skip to content

Instantly share code, notes, and snippets.

@stormbeta
Last active October 18, 2018 17:15
Show Gist options
  • Save stormbeta/c9ada0489cb7a215a4568c637e8056e2 to your computer and use it in GitHub Desktop.
Save stormbeta/c9ada0489cb7a215a4568c637e8056e2 to your computer and use it in GitHub Desktop.
Config Helper for kubectl
#!/usr/bin/bash
# Intended for use in your bashrc config
function reload-kubeconfigs {
# Combine kubeconfigs into ':'-delimited list as KUBECONFIG, which will be auto-merged by kubectl
local default="${HOME}/.kube/config"
local config_dir="${HOME}/.kube/config.d"
local config_paths=""
[[ ! -d "$config_dir" ]] && mkdir -p "$config_dir"
function __join { local IFS="$1"; shift; echo "$*"; }
if [[ -n "$(ls "$config_dir")" ]]; then
local configs=( "${config_dir}/"* )
config_paths="$(__join : "${configs[@]}")"
fi
if [[ -f "$default" ]]; then
config_paths="${default}:${config_paths}"
fi
export KUBECONFIG="$config_paths"
}
reload-kubeconfigs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment