Commit 142c8354 authored by Waqar Ahmed's avatar Waqar Ahmed

Use a configmap for a script to take backup of postgres

parent 1f15d72c
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 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
...@@ -12,7 +28,7 @@ spec: ...@@ -12,7 +28,7 @@ spec:
name: "pre-upgrade-hook2" name: "pre-upgrade-hook2"
spec: spec:
restartPolicy: Never restartPolicy: Never
serviceAccountName: {{ template "nextcloud.serviceAccountName" }} serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
containers: containers:
- name: {{ .Chart.Name }}-postgres-backup - name: {{ .Chart.Name }}-postgres-backup
image: "postgres:13.1" image: "postgres:13.1"
...@@ -33,4 +49,20 @@ spec: ...@@ -33,4 +49,20 @@ spec:
mountPath: /var/lib/postgresql/data mountPath: /var/lib/postgresql/data
- name: postgres-backup - name: postgres-backup
mountPath: /postgres_backups 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"
...@@ -12,8 +12,8 @@ spec: ...@@ -12,8 +12,8 @@ spec:
name: "pre-upgrade-hook1" name: "pre-upgrade-hook1"
spec: spec:
restartPolicy: Never restartPolicy: Never
serviceAccountName: {{ template "nextcloud.serviceAccountName" }} serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}"
containers: containers:
- name: kubectl - name: kubectl
image: "bitnami/kubectl:1.19" 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"]
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: {{ template "nextcloud.serviceAccountName" }} name: "{{ template "nextcloud.serviceAccountName" . }}"
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
--- ---
...@@ -9,14 +9,14 @@ metadata: ...@@ -9,14 +9,14 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding kind: RoleBinding
metadata: metadata:
name: {{ .Release.Name }}-service-account-role-binding name: "{{ .Release.Name }}-service-account-role-binding"
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: {{ template "nextcloud.serviceAccountName" }} name: "{{ template "nextcloud.serviceAccountName" . }}"
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
roleRef: roleRef:
kind: Role kind: Role
name: spinupcontainers name: "{{ .Release.Name }}-service-account-role"
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
--- ---
...@@ -24,7 +24,7 @@ roleRef: ...@@ -24,7 +24,7 @@ roleRef:
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: Role kind: Role
metadata: metadata:
name: {{ .Release.Name }}-service-account-role name: "{{ .Release.Name }}-service-account-role"
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
rules: rules:
- apiGroups: - apiGroups:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment