Created
May 26, 2022 14:45
-
-
Save mattmattox/6fd74b9f857ebbdcc29a167f46e9b591 to your computer and use it in GitHub Desktop.
dump-k8s-cluster.sh
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 | |
objects=`kubectl api-resources --verbs=list --namespaced -o name` | |
for namespace in `kubectl get ns -o name | awk -F '/' '{print $2}'` | |
do | |
echo "Namespace: $namespace" | |
mkdir -p namespace/"$namespace" | |
for object in $objects | |
do | |
mkdir -p namespace/"$namespace"/"$object" | |
echo "Object: $object" | |
for item in `kubectl -n $namespace get $object -o name | awk -F '/' '{print $2}'` | |
do | |
echo "item: $item" | |
kubectl -n $namespace get $object $item -o yaml > namespace/"$namespace"/"$object"/"$item".yaml | |
done | |
done | |
done | |
mkdir -p clusterobjects | |
for clusterobject in `kubectl api-resources --verbs=list --namespaced=false -o name` | |
do | |
echo "Cluster Object: $clusterobject" | |
mkdir -p clusterobjects/"$clusterobject" | |
for clusteritem in `kubectl get $clusterobject -o name | awk -F '/' '{print $2}'` | |
do | |
echo "Cluster Item: $clusteritem" | |
kubectl get $clusterobject $clusteritem -o yaml > clusterobjects/"$clusterobject"/"$clusteritem".yaml | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment