Forked from dobesv/gist:4f76a2095a3aa8bc20eda6b3a8e455b3
Created
March 20, 2023 06:38
-
-
Save khoahuynhdev/974282a5e06254977d7079ef94e8b323 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 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
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