Use a configmap for a script to take backup of postgres

This commit is contained in:
Waqar Ahmed 2020-12-12 19:01:32 +05:00
parent 1f15d72cf0
commit 142c8354f8
3 changed files with 41 additions and 9 deletions

View File

@ -1,3 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "postgres-backup-hook-config-map"
data:
entrypoint.sh: |-
#!/bin/sh
cmd="/docker-entrypoint.sh postgres"
eval "${cmd}" & disown;
until pg_isready; do
sleep 5;
done;
pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName"}} > /postgres_backups/update_dump;
---
apiVersion: batch/v1
kind: Job
metadata:
@ -12,7 +28,7 @@ spec:
name: "pre-upgrade-hook2"
spec:
restartPolicy: Never
serviceAccountName: {{ template "nextcloud.serviceAccountName" }}
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
containers:
- name: {{ .Chart.Name }}-postgres-backup
image: "postgres:13.1"
@ -33,4 +49,20 @@ spec:
mountPath: /var/lib/postgresql/data
- name: postgres-backup
mountPath: /postgres_backups
command: ['sh', '-c', "/docker-entrypoint.sh; pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName"}} > /postgres_backups/update_dump;"]
- name: backup-script-configmap
mountPath: /bin/backup_entrypoint.sh
readOnly: true
subPath: entrypoint.sh
command:
- "/bin/backup_entrypoint.sh"
volumes:
- name: postgres-data
hostPath:
path: {{ template "configuredPostgresHostPath" . }}
- name: postgres-backup
hostPath:
path: {{ template "configuredBackupPostgresHostPath" . }}
- name: backup-script-configmap
configMap:
defaultMode: 0700
name: "postgres-backup-hook-config-map"

View File

@ -12,8 +12,8 @@ spec:
name: "pre-upgrade-hook1"
spec:
restartPolicy: Never
serviceAccountName: {{ template "nextcloud.serviceAccountName" }}
serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
containers:
- name: kubectl
image: "bitnami/kubectl:1.19"
command: ["delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"]
command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"]

View File

@ -1,7 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "nextcloud.serviceAccountName" }}
name: "{{ template "nextcloud.serviceAccountName" . }}"
namespace: {{ .Release.Namespace }}
---
@ -9,14 +9,14 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}-service-account-role-binding
name: "{{ .Release.Name }}-service-account-role-binding"
subjects:
- kind: ServiceAccount
name: {{ template "nextcloud.serviceAccountName" }}
name: "{{ template "nextcloud.serviceAccountName" . }}"
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
name: spinupcontainers
name: "{{ .Release.Name }}-service-account-role"
apiGroup: rbac.authorization.k8s.io
---
@ -24,7 +24,7 @@ roleRef:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Release.Name }}-service-account-role
name: "{{ .Release.Name }}-service-account-role"
namespace: {{ .Release.Namespace }}
rules:
- apiGroups: