Last active
October 9, 2020 09:23
-
-
Save davidcollom/5949ddf844b02c4f70f869047ff02615 to your computer and use it in GitHub Desktop.
export k8s cluster
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
#!/usr/bin/env bash | |
EXCLUDE_RESOURCES="pods|endpoints|controllerrevisions.apps|replicasets|events" | |
for ns in $(kubectl get ns -o json | jq -r '.items[].metadata.name'); do | |
for obj in $(kubectl api-resources --namespaced -o name | grep -vE "${EXCLUDE_RESOURCES}"); do | |
for name in $(kubectl -n $ns get $obj -o json | jq -r '.items[].metadata.name'); do | |
echo ${ns}/${obj}/${name} | |
mkdir -p ${ns}/${obj}; | |
kubectl -n $ns get $obj $name -o yaml \ | |
| yq d - 'metadata.resourceVersion' \ | |
| yq d - 'metadata.uid' \ | |
| yq d - 'metadata.annotations."kubectl.kubernetes.io/last-applied-configuration"' \ | |
| yq d - 'metadata.annotations."deprecated.daemonset.template.generation"' \ | |
| yq d - 'metadata.annotations."kubernetes.digitalocean.com/load-balancer-id"' \ | |
| yq d - 'metadata.annotations."deployment.kubernetes.io/revision"' \ | |
| yq d - 'metadata.generation' \ | |
| yq d - 'metadata.finalizers' \ | |
| yq d - 'metadata.creationTimestamp' \ | |
| yq d - 'status' \ | |
| yq d - 'metadata.selfLink' > ${ns}/${obj}/${name}.yaml | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment