Skip to content

Instantly share code, notes, and snippets.

@davidcollom
Last active October 9, 2020 09:23
Show Gist options
  • Save davidcollom/5949ddf844b02c4f70f869047ff02615 to your computer and use it in GitHub Desktop.
Save davidcollom/5949ddf844b02c4f70f869047ff02615 to your computer and use it in GitHub Desktop.
export k8s cluster
#!/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