Skip to content

Instantly share code, notes, and snippets.

@eznix86
Created March 20, 2025 05:21
Show Gist options
  • Select an option

  • Save eznix86/1c8e69d14bebc2fd691c862d7633616a to your computer and use it in GitHub Desktop.

Select an option

Save eznix86/1c8e69d14bebc2fd691c862d7633616a to your computer and use it in GitHub Desktop.
####################
#
# Author: Bruno Bernard (eznix86)
#
####################
# Note on how to merge all kubeconfig into one place
# Your default configuration will be fetched by kubectl is inside of ~/.kube/config
# Gather all of them, it should be paths colon (:) seperated without spaces
export KUBECONFIG=~/.kube/config:~/documents/configs-a.txt:~/documents/configs-b.txt:~/kubeconfigs/aws/config
# Check if all is working as you expect
kubectl config view
# Write to disk
kubectl config view --flatten > ~/.kube/config.temp
# Backup your general configuration (if you want)
cp ~/.kube/config ~/.kube/config.bak
# Override the original clusters kubeconfigs
mv ~/.kube/config.temp ~/.kube/config
# Only you can read or write to it
chmod 600 ~/.kube/config
# Profit
kubectl config get-clusters
# You switch cluster whenever you want
kubectl config use-context aws
kubectl config use-context homelab
# or even rename the context, as sometimes it is known as default
kubectl config rename-context default tiny-homelab # renames default to tiny-homelab
# There you go:
kubectl config get-clusters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment