Created
December 20, 2019 06:11
-
-
Save dobesv/4f76a2095a3aa8bc20eda6b3a8e455b3 to your computer and use it in GitHub Desktop.
Example of a kubernetes cron job that dumps a postgres database and copies it to s3
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
apiVersion: batch/v1beta1 | |
kind: CronJob | |
metadata: | |
name: postgres-backup | |
spec: | |
schedule: "0 12 * * *" | |
jobTemplate: | |
spec: | |
backoffLimit: 0 | |
template: | |
spec: | |
initContainers: | |
- name: dump | |
image: postgres:12.1-alpine | |
volumeMounts: | |
- name: data | |
mountPath: /backup | |
args: | |
- pg_dump | |
- "-Fc" | |
- "-f" | |
- "/backup/redash-postgres.pgdump" | |
- "-Z" | |
- "9" | |
- "-v" | |
- "-h" | |
- "postgres" | |
- "-U" | |
- "postgres" | |
- "-d" | |
- "redash" | |
env: | |
- name: PGPASSWORD | |
valueFrom: | |
secretKeyRef: | |
# Retrieve postgres password from a secret | |
name: postgres | |
key: POSTGRES_PASSWORD | |
containers: | |
- name: save | |
image: mesosphere/aws-cli | |
volumeMounts: | |
- name: data | |
mountPath: /backup | |
args: | |
- aws | |
- s3 | |
- cp | |
- "/backup/redash-postgres.pgdump" | |
- "s3://redash-postgres-backups/redash-postgres.pgdump" | |
envFrom: | |
- secretRef: | |
# Must contain AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION | |
name: s3-backup-credentials | |
restartPolicy: Never | |
volumes: | |
- name: data | |
emptyDir: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
- aws
in line 46 should be removed.