-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-statefulsets.yaml
More file actions
116 lines (116 loc) · 2.47 KB
/
db-statefulsets.yaml
File metadata and controls
116 lines (116 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
ports:
- port: 5432
name: postgres
clusterIP: None
selector:
app: postgres
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
serviceName: "postgres"
replicas: 1
minReadySeconds: 10
template:
metadata:
labels:
app: postgres
spec:
terminationGracePeriodSeconds: 10
containers:
- name: postgres
image: postgres:17.5
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
env:
- name: POSTGRES_HOST_AUTH_METHOD
valueFrom:
configMapKeyRef:
name: db-configmaps
key: POSTGRES_HOST_AUTH_METHOD
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: db-secrets
key: POSTGRES_DB
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
storageClassName: csi-hostpath-sc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: backup-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
storageClassName: csi-hostpath-sc
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: postgres-dump
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: postgres-dump
image: postgres:17.5
command:
- /bin/sh
- -c
- |
pg_dump -h postgres -U $POSTGRES_USER -d $POSTGRES_DB > /postgresdump/dump.sql
volumeMounts:
- name: backup-storage
mountPath: /postgresdump
env:
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: db-secrets
key: POSTGRES_USER
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: db-secrets
key: POSTGRES_DB
restartPolicy: OnFailure
volumes:
- name: backup-storage
persistentVolumeClaim:
claimName: backup-pvc