Skip to content

Instantly share code, notes, and snippets.

@ngeorger
Last active December 29, 2023 04:55
Show Gist options
  • Save ngeorger/62ee4e5369d8609524b88288fd4b88c3 to your computer and use it in GitHub Desktop.
Save ngeorger/62ee4e5369d8609524b88288fd4b88c3 to your computer and use it in GitHub Desktop.
Backup or dump kubernetes secrets by namespaces
#!/usr/bin/bash
# This script is based on this one https://kevinsimper.medium.com/how-to-dump-all-kubernetes-secrets-to-yaml-files-b5afcf2d1f56
# But also it reads every namespace in your current default context and dumps it's secrets as a file named as the namespace and yml extension
# Tested on non-productive environments.
kubectl get namespaces | awk '{print $1}' | xargs -I{} sh -c 'kubectl get secrets -o yaml -n "$1" --no-headers >> "$1.yaml"' - {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment