pg backup as well
This commit is contained in:
		| @@ -1,32 +0,0 @@ | ||||
| apiVersion: batch/v1beta1 | ||||
| kind: CronJob | ||||
| metadata: | ||||
|   name: postgres-backup | ||||
| spec: | ||||
|   # Backup the database every day at 2AM | ||||
|   schedule: "0 2 * * *" | ||||
|   jobTemplate: | ||||
|     spec: | ||||
|       template: | ||||
|         spec: | ||||
|           containers: | ||||
|           - name: postgres-backup | ||||
|             image: postgres:12 | ||||
|             command: ["/bin/sh"] | ||||
|             args: ["-c", 'echo "$PGPASS" > /root/.pgpass && chmod 600 /root/.pgpass && pg_dump -U postgres_admin -h postgres test_database > /var/backups/backup-$(date +"%m-%d-%Y-%H-%M").sql'] | ||||
|             env: | ||||
|             - name: PGPASS | ||||
|               valueFrom: | ||||
|                 secretKeyRef: | ||||
|                   name: pgpass | ||||
|                   key: pgpass | ||||
|             volumeMounts: | ||||
|             - mountPath: /var/backups | ||||
|               name: postgres-storage | ||||
|           restartPolicy: Never | ||||
|           volumes: | ||||
|           - name: postgres-storage | ||||
|             hostPath: | ||||
|             # Ensure the file directory is created. | ||||
|               path: /var/volumes/postgres-backups | ||||
|               type: DirectoryOrCreate | ||||
							
								
								
									
										37
									
								
								infrastructure/backup/postgres/cronjob.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								infrastructure/backup/postgres/cronjob.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| apiVersion: batch/v1 | ||||
| kind: CronJob | ||||
| metadata: | ||||
|   name: postgres-backup | ||||
| spec: | ||||
|   # Backup the database every day at 1AM | ||||
|   schedule: "0 1 * * *" | ||||
|   jobTemplate: | ||||
|     spec: | ||||
|       template: | ||||
|         spec: | ||||
|           containers: | ||||
|           - name: postgres-backup | ||||
|             image: postgres:15 | ||||
|             command: ["/bin/sh"] | ||||
|             args: | ||||
|               - "-c" | ||||
|               - >- | ||||
|                 echo "$postgress_password" > /root/.pgpass | ||||
|                 && | ||||
|                 chmod 600 /root/.pgpass | ||||
|                 && | ||||
|                 pg_dumpall -U postgres -h postgrespostgres-postgresql.postgres > /backup/backup-$(date +"%m-%d-%Y-%H-%M").sql | ||||
|             env: | ||||
|             - name: PGpostgress_passwordPASS | ||||
|               valueFrom: | ||||
|                 secretKeyRef: | ||||
|                   name: postgres-password | ||||
|                   key: password | ||||
|             volumeMounts: | ||||
|             - mountPath: /backup | ||||
|               name: postgres-backup-claim | ||||
|           restartPolicy: Never | ||||
|           volumes: | ||||
|           - name: postgres-backup-claim | ||||
|             persistentVolumeClaim: | ||||
|               claimName: postgres-backup-claim | ||||
							
								
								
									
										9
									
								
								infrastructure/backup/postgres/kustomization.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								infrastructure/backup/postgres/kustomization.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| apiVersion: kustomize.config.k8s.io/v1beta1 | ||||
| kind: Kustomization | ||||
|  | ||||
| namespace: backup | ||||
|  | ||||
| resources: | ||||
|   - postgres.sealedsecret.yaml | ||||
|   - pvc.yaml | ||||
|   - cronjob.yaml | ||||
							
								
								
									
										21
									
								
								infrastructure/backup/postgres/postgres.sealedsecret.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								infrastructure/backup/postgres/postgres.sealedsecret.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| { | ||||
|   "kind": "SealedSecret", | ||||
|   "apiVersion": "bitnami.com/v1alpha1", | ||||
|   "metadata": { | ||||
|     "name": "postgres-password", | ||||
|     "namespace": "backup", | ||||
|     "creationTimestamp": null | ||||
|   }, | ||||
|   "spec": { | ||||
|     "template": { | ||||
|       "metadata": { | ||||
|         "name": "postgres-password", | ||||
|         "namespace": "backup", | ||||
|         "creationTimestamp": null | ||||
|       } | ||||
|     }, | ||||
|     "encryptedData": { | ||||
|       "password": "AgBKXybtQWxHVX0UeQ9z5VOSJp9dadp+j+8VxBzyh37BdfLA9l5YppOWgK2RpmQmFmcrrxr7u2SgyJ4rP60n0r8LHLcmPTXAUJe5b07HTVOLn8Q4C9ObEkWVXBycmI5Kc8vHZ+OW8T3s/QqrnLIlQPOq56mjsWjO24O/72aUl4IzlrSq3NYPAMpQOwfgoam/4ZaHed6+Im40eQalkEWRlk5KOkSayWsrNJNccAhnZ8JapCP25pVVfz5xJc9286jNqTCgGt1Ez3xTXbd3LPI2QgeonIPU9zqlXeQgjS/UuAIuKyEW7ypD2/7lLoU1Yk4XMzIreVSrYgfy7ylnC++FPZBI+32/ocbEgpXPX9O/gb2tQLANVEn9BwVyPe3MW/vB63ryyfhtrPQbNJCJNnwKlsoS+HcVYBGAAtjdUYD4/2fKabH7Th2SlMIJvGBwhxpJo1bnblHoTUQ/Ao5gaUIcZC0qCnd9ZKVRKwtFsJrgqnEAapd9dNdDu9RBxVKAUa0TS+ahnXBaC87lvydb/9PxLz+J7E27oInt9coFEHpaZFNdt0QJXUqs3DF0JO7ll3wC+R1iDUWRY3NKf/bpiGgkwk3VtUkIXcW5biaD7lF8inrLVzktvQGET/CbYre5ws9qj5xF4NUYUivYexiP8isScnbrys671GizUjxFoPQpWotEHmZ9DNsIYOF3OvewKjDllpo1izKmY1Y=" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										13
									
								
								infrastructure/backup/postgres/pvc.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								infrastructure/backup/postgres/pvc.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| kind: PersistentVolumeClaim | ||||
| apiVersion: v1 | ||||
|  | ||||
| metadata: | ||||
|   name: postgres-backup-claim | ||||
|  | ||||
| spec: | ||||
|   storageClassName: nfs-client | ||||
|   accessModes: | ||||
|     - ReadWriteOnce | ||||
|   resources: | ||||
|     requests: | ||||
|       storage: 10Gi | ||||
| @@ -4,3 +4,4 @@ resources: | ||||
|   - secrets.application.yaml | ||||
|   - backup.application.yaml | ||||
|   - prune.application.yaml | ||||
|   - postgres.backup.application.yaml | ||||
|   | ||||
							
								
								
									
										18
									
								
								kluster-deployments/backup/postgres.backup.application.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								kluster-deployments/backup/postgres.backup.application.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| apiVersion: argoproj.io/v1alpha1 | ||||
| kind: Application | ||||
| metadata: | ||||
|   name: postgres-backup-application | ||||
|   namespace: argocd | ||||
| spec: | ||||
|   project: infrastructure | ||||
|   source: | ||||
|     repoURL: https://github.com/moll-re/k3s-infra.git | ||||
|     targetRevision: main | ||||
|     path: infrastructure/backup/postgres | ||||
|   destination: | ||||
|     server: https://kubernetes.default.svc | ||||
|     namespace: backup | ||||
|   syncPolicy: | ||||
|     automated: | ||||
|       prune: true | ||||
|       selfHeal: true | ||||
		Reference in New Issue
	
	Block a user