Created
March 15, 2024 17:55
-
-
Save acarmisc/8fb7fe99529b7cca7342d8f8646b2bfc to your computer and use it in GitHub Desktop.
Export each kubernetes context to single file
This file contains 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 | |
# create target folder | |
mkdir -p contexts | |
# get all contexts name | |
contexts=$(kubectl config get-contexts -o=name) | |
# cycle on each context | |
for context in $contexts; do | |
slug=$(echo "$context" | tr -s '[:upper:]' '[:lower:]' | tr -s '[:space:]' '-' | tr -d ':' | tr '/' '-') | |
slug=${slug%-} | |
kubectl config view --minify --flatten --context="$context" > "contexts/${slug}.kubeconfig" | |
echo "Context $context exported to contexts/${slug}.kubeconfig" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment