Last active
January 12, 2021 13:07
-
-
Save gneissguise/a5d407207a06edd8c7104812cb983445 to your computer and use it in GitHub Desktop.
Kubernetes Cluster Backup Script
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 | |
## Run on Master/Control Plane! | |
IFS=$'\n' | |
arr1=($(kubectl get -o=name namespace)) | |
for ns in "${arr1[@]}"; do | |
names="${ns##*/}" | |
echo "$names" | |
arr2=($(kubectl get -o=name pvc,configmap,serviceaccount,secret,ingress,service,deployment,statefulset,hpa,job,cronjob,daemonset -n $names)) | |
for rs in "${arr2[@]}"; do | |
echo "..$rs" | |
mkdir -p "$names/$(dirname $rs)" | |
kubectl get -o=yaml $rs -n $names > "$names/$rs.yaml" | |
done | |
done | |
arr3=($(kubectl get -o=name storageclass,persistentvolume,clusterrolebinding,clusterrole,rolebinding,role,serviceaccount)) | |
for rl in "${arr3[@]}"; do | |
echo "$rl" | |
mkdir -p "$(dirname $rl)" | |
kubectl get -o=yaml $rl -n $names > "$rl.yaml" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed a quick and easy way to export my k8s configs to yaml for a migration, so I wrote this script.