Skip to content

Commit 5c95bf4

Browse files
committed
chore(postgresql-cluster): add pgbackup
1 parent 56ce845 commit 5c95bf4

5 files changed

Lines changed: 68 additions & 42 deletions

File tree

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/_helpers.tpl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Create the name of the service account to use.
4343
{{- end -}}
4444

4545
{{/*
46-
Return true if a cronjob object should be created for Postgresql HA patroni
46+
Return true if a cronjob object should be created for Postgresql HA patroni ## TODO feature
4747
*/}}
4848
{{- define "patroni.createCronJob" -}}
49-
{{- if and .Values.walG.enable }}
49+
{{- if and .Values.walG.enabled }}
5050
{{- true -}}
5151
{{- else -}}
5252
{{- end -}}
@@ -115,13 +115,14 @@ Create patroni envs.
115115
fieldPath: metadata.name
116116
- name: PATRONI_POSTGRESQL_DATA_DIR
117117
value: "{{ .Values.persistentVolume.mountPath }}/data"
118+
- name: PGDATA
119+
value: "{{ .Values.persistentVolume.mountPath }}/data"
118120
- name: PATRONI_POSTGRESQL_PGPASS
119121
value: /tmp/pgpass
120122
- name: PATRONI_POSTGRESQL_LISTEN
121123
value: '0.0.0.0:5432'
122124
- name: PATRONI_RESTAPI_LISTEN
123125
value: '0.0.0.0:8008'
124-
125126
- name: DATABASE_NAME
126127
valueFrom:
127128
secretKeyRef:
@@ -137,20 +138,15 @@ Create patroni envs.
137138
secretKeyRef:
138139
name: {{ template "patroni.fullname" . }}
139140
key: data-password
140-
141141
{{- end -}}
142142

143143
{{/*
144144
Create walg envs.
145145
*/}}
146146
{{- define "walg.envs" }}
147-
{{- if .Values.walG.enable }}
147+
{{- if .Values.walG.enabled }}
148148
- name: USE_WALG
149-
value: {{ .Values.walG.enable | quote }}
150-
{{- if .Values.walG.scheduleCronJob }}
151-
- name: BACKUP_SCHEDULE
152-
value: {{ .Values.walG.scheduleCronJob | quote}}
153-
{{- end }}
149+
value: {{ .Values.walG.enabled | quote }}
154150
{{- if .Values.walG.retainBackups }}
155151
- name: BACKUP_NUM_TO_RETAIN
156152
value: {{ .Values.walG.retainBackups | quote}}
@@ -165,7 +161,7 @@ Create walg envs.
165161
{{- end }}
166162
{{- if .Values.walG.s3.used }}
167163
- name: AWS_ACCESS_KEY_ID
168-
value: {{ .Values.walG.s3.awsAccessKeyId | quote }}
164+
value: {{ .Values.walG.s3.awsAccessKeyID | quote }}
169165
- name: AWS_SECRET_ACCESS_KEY
170166
value: {{ .Values.walG.s3.awsSecretAccessKey | quote }}
171167
- name: WALG_S3_PREFIX

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/cronjob.yaml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ metadata:
1919
{{- end }}
2020

2121
spec:
22-
schedule: "*/1 * * * *"
22+
schedule: "{{ .Values.walG.scheduleCronJob }}"
2323
failedJobsHistoryLimit: 1
2424
successfulJobsHistoryLimit: 1
2525
jobTemplate:
@@ -30,29 +30,14 @@ spec:
3030
containers:
3131
- name: {{ .Chart.Name }}-backup
3232
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
33-
imagePullPolicy: Always
34-
#imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
33+
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
3534
command:
3635
- /usr/bin/env
3736
- bash
3837
- -c
3938
- |
40-
echo "sleeping ...."
41-
sleep 10000
42-
echo "Successfull"
43-
init-stack /opt/drycc/wal-g/bin/wal-g backup-push
44-
init-stack /opt/drycc/wal-g/bin/wal-g delete
39+
curl "http://${REPLHOST}:9000/pg_backup"
4540
env:
46-
{{- include "walg.envs" . | indent 14 }}
47-
- name: PGHOST
48-
value: {{ include "patroni.fullname" . }}-repl
49-
- name: PGPASSWORD
50-
valueFrom:
51-
secretKeyRef:
52-
name: {{ template "patroni.fullname" . }}
53-
key: password-replication
54-
- name: PGUSER
55-
value: standby
56-
- name: PGPORT
57-
value: "5432"
41+
- name: REPLHOST
42+
value: {{ include "patroni.fullname" . }}-repl
5843
{{- end -}}

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/statefulset.yaml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ spec:
5656
# fsGroup: postgres
5757
env:
5858
{{- include "patroni.envs" . | indent 8 }}
59+
{{- if .Values.walG.enabled }}
60+
{{- include "walg.envs" . | indent 8 }}
61+
{{- end }}
5962
{{- if .Values.env }}
6063
{{- range $key, $val := .Values.env }}
6164
- name: {{ $key | quote | upper }}
@@ -156,7 +159,43 @@ spec:
156159
resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
157160
{{- end }}
158161
{{- end }}
159-
{{- with .Values.nodeSelector }}
162+
{{- if .Values.walG.enabled }}
163+
- name: {{ .Chart.Name }}-backup
164+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
165+
imagePullPolicy: {{ .Values.image.pullPolicy }}
166+
# securityContext:
167+
# runAsUser: postgres
168+
# fsGroup: postgres
169+
command:
170+
- /usr/bin/env
171+
- bash
172+
- -c
173+
- |
174+
python3 /opt/drycc/postgresql/pgbackup.py 0.0.0.0 9000
175+
env:
176+
{{- include "walg.envs" . | indent 8 }}
177+
- name: PGHOST
178+
value: localhost
179+
- name: PGPASSWORD
180+
valueFrom:
181+
secretKeyRef:
182+
name: {{ template "patroni.fullname" . }}
183+
key: password-superuser
184+
- name: PGUSER
185+
value: postgres
186+
- name: PGDATABASE
187+
value: postgres
188+
- name: PGPORT
189+
value: "5432"
190+
- name: PGDATA
191+
value: "{{ .Values.persistentVolume.mountPath }}/data"
192+
ports:
193+
- containerPort: 9000
194+
volumeMounts:
195+
- name: storage-volume
196+
mountPath: "{{ .Values.persistentVolume.mountPath }}"
197+
{{- end }}
198+
{{- with .Values.nodeSelector }}
160199
nodeSelector:
161200
{{ toYaml . | indent 8 }}
162201
{{- end }}

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/svc-relp.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ spec:
1818
cluster-name: {{ template "patroni.fullname" . }}
1919
role: replica
2020
ports:
21-
- port: 5432
22-
targetPort: 5432
21+
- name: postgresql
22+
port: 5432
23+
targetPort: 5432
24+
- name: pgbackup
25+
port: 9000
26+
targetPort: 9000

addons/postgresql-cluster/15/chart/postgresql-cluster/values.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ preInitScript: |
5656
- host all tea_mon 127.0.0.1/32 trust
5757
- host all all 0.0.0.0/0 scram-sha-256
5858
- host replication ${PATRONI_REPLICATION_USERNAME} 0.0.0.0/0 scram-sha-256
59+
- host replication postgres 0.0.0.0/0 scram-sha-256
5960
parameters:
6061
wal_level: hot_standby
6162
hot_standby: "on"
@@ -69,8 +70,8 @@ preInitScript: |
6970
wal_log_hints: "on"
7071
track_commit_timestamp: "off"
7172
archive_mode: "on"
72-
archive_timeout: 1800s
73-
archive_command: /bin/true
73+
archive_timeout: 300s
74+
archive_command: sh /opt/drycc/postgresql/walbackup.sh %f
7475
# timescaledb.license: 'timescale'
7576
shared_preload_libraries: 'auto_explain,pg_stat_statements'
7677
log_destination: 'csvlog'
@@ -222,9 +223,9 @@ metrics:
222223
memory: 512Mi
223224
walG:
224225
# Specifies whether Wal-E should be enabled
225-
enable: false
226+
enabled: true
226227
# Cron schedule for doing base backups
227-
scheduleCronJob: 00 01 * * *
228+
scheduleCronJob: "*/5 * * * *"
228229
# Amount of base backups to retain
229230
retainBackups: 2
230231
# Name of the secret that holds the credentials to the bucket
@@ -236,10 +237,11 @@ walG:
236237
# to consider WAL-E restore instead of pg_basebackup
237238
backupThresholdPercentage: 30
238239
s3:
239-
awsAccessKeyID: "xxx"
240-
awsSecretAccessKey: "xx"
241-
walGS3Prefix: "xxx"
242-
awsEndpoint: "xxx"
240+
used: true
241+
awsAccessKeyID: "minioadmin"
242+
awsSecretAccessKey: "minioadmin"
243+
walGS3Prefix: "s3://pg1"
244+
awsEndpoint: "http://10.10.2.11:9000"
243245
awsS3ForcePathStyle: "true"
244246
awsRegion: dx-1
245247

0 commit comments

Comments
 (0)