-
-
Save naviat/81417e63eb840de94fed8bbc686843b5 to your computer and use it in GitHub Desktop.
Simple k8s backup if you don't yet have k8up or velero in place. Use with caution. Extend extracted values as needed.
This file contains hidden or 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 | |
set -o pipefail -o errexit -o nounset -o errtrace | |
mkdir -p backup/ | |
for ns in $(kubectl get ns --no-headers -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'); do | |
kubectl --namespace="${ns}" get -o=yaml role,rolebinding,secret,configmap | \ | |
yq eval ' | |
del( | |
.items.[].spec.clusterIP, | |
.items.[].metadata.uid, | |
.items.[].metadata.selfLink, | |
.items.[].metadata.resourceVersion, | |
.items.[].metadata.creationTimestamp, | |
.items.[].metadata.generation, | |
.items.[].metadata.managedFields, | |
.items.[].status, | |
.items.[].spec.template.spec.securityContext, | |
.items.[].spec.template.spec.dnsPolicy, | |
.items.[].spec.template.spec.terminationGracePeriodSeconds, | |
.items.[].spec.template.spec.restartPolicy | |
)' - > "./backup/${ns}.yaml" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment