Skip to content

Instantly share code, notes, and snippets.

@mbesida
Last active March 2, 2021 17:18
Show Gist options
  • Save mbesida/cc95e89376d5acd20e54d5b7939576ad to your computer and use it in GitHub Desktop.
Save mbesida/cc95e89376d5acd20e54d5b7939576ad to your computer and use it in GitHub Desktop.
Merge kubectl config files

To merge existing kubectl config with a new one we can use following script:

cp ~/.kube/config ~/.kube/config.old && \
KUBECONFIG=~/.kube/config:/path_to_new_config kubectl config view --flatten > /tmp_config && \
mv /tmp_config ~/.kube/config

/tmp_config and /path_to_new_config are just random names which could be changed. The script will create a file ~/.kube/config.old with old version of kubectl config

KUBECONFIG is an env variable that could be used to set the config file for kubectl, kubectl looks into this env variable and if not found uses the default config from ~/.kube/config. Elements in KUBECONFIG should be divided by : for UNIX based systems where each element is a path to a file with kubectl config

Taken from https://jacobtomlinson.dev/posts/2019/how-to-merge-kubernetes-kubectl-config-files/

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