-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathpatroni-deployment.yaml
302 lines (302 loc) · 8.93 KB
/
patroni-deployment.yaml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
apiVersion: template.openshift.io/v1
kind: Template
metadata:
annotations:
description: |-
Patroni Postgresql database cluster, with persistent storage.
iconClass: icon-postgresql
openshift.io/display-name: Patroni Postgresql (Persistent)
openshift.io/long-description: This template deploys a patroni postgresql HA
cluster with persistent storage.
tags: postgresql
name: patroni-pgsql-persistent
labels:
app: ${NAME}${SUFFIX}
phase: deploy
app.kubernetes.io/instance: ${NAME}${SUFFIX}
app.kubernetes.io/component: database
app.kubernetes.io/name: patroni
app.kubernetes.io/managed-by: template
objects:
# It doesn't seem to be used/needed - remote it?
#- apiVersion: v1
# kind: Service
# metadata:
# creationTimestamp: null
# labels:
# cluster-name: ${NAME}${SUFFIX}
# name: ${NAME}${SUFFIX}
# spec:
# ports:
# - name: 'postgresql'
# port: 5432
# protocol: TCP
# targetPort: 5432
# sessionAffinity: None
# type: ClusterIP
# status:
# loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
cluster-name: ${NAME}${SUFFIX}
name: ${NAME}-master${SUFFIX}
spec:
ports:
- port: 5432
# name: 'postgresql'
protocol: TCP
targetPort: 5432
selector:
cluster-name: ${NAME}${SUFFIX}
role: master
app.kubernetes.io/name: patroni
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
#- apiVersion: v1
# kind: Service
# metadata:
# creationTimestamp: null
# labels:
# cluster-name: ${NAME}${SUFFIX}
# name: ${NAME}-replica${SUFFIX}
# spec:
# ports:
# - port: 5432
## name: 'postgresql'
# protocol: TCP
# targetPort: 5432
# selector:
# cluster-name: ${NAME}${SUFFIX}
# app.kubernetes.io/name: patroni
# role: replica
# sessionAffinity: None
# type: ClusterIP
# status:
# loadBalancer: {}
# - apiVersion: v1
# kind: ConfigMap
# metadata:
# name: ${NAME}${SUFFIX}-config
# - apiVersion: v1
# kind: ConfigMap
# metadata:
# name: ${NAME}${SUFFIX}-leader
- apiVersion: apps/v1
kind: StatefulSet
metadata:
creationTimestamp: null
generation: 3
labels:
cluster-name: ${NAME}${SUFFIX}
name: ${NAME}${SUFFIX}
spec:
podManagementPolicy: OrderedReady
replicas: ${{REPLICAS}}
revisionHistoryLimit: 10
selector:
matchLabels:
statefulset: ${NAME}${SUFFIX}
serviceName: ${NAME}${SUFFIX}
template:
metadata:
creationTimestamp: null
labels:
statefulset: ${NAME}${SUFFIX}
cluster-name: ${NAME}${SUFFIX}
app.kubernetes.io/name: patroni
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: statefulset
operator: In
values:
- ${NAME}${SUFFIX}
topologyKey: "kubernetes.io/hostname"
containers:
- env:
#TODO: Remove POD_IP in favor of PATRONI_KUBERNETES_POD_IP
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
# - name: PATRONI_KUBERNETES_USE_ENDPOINTS
# value: 'true'
# - name: PATRONI_KUBERNETES_POD_IP
# valueFrom:
# fieldRef:
# apiVersion: v1
# fieldPath: status.podIP
# - name: PATRONI_KUBERNETES_PORTS
# value: '{[{"name": "postgresql", "port": 5432}]}'
- name: PATRONI_KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: PATRONI_KUBERNETES_LABELS
value: '{"cluster-name": "${NAME}${SUFFIX}", "app.kubernetes.io/name": "patroni"}'
- name: PATRONI_SUPERUSER_USERNAME
valueFrom:
secretKeyRef:
key: superuser-username
name: ${NAME}${SUFFIX}
- name: PATRONI_SUPERUSER_PASSWORD
valueFrom:
secretKeyRef:
key: superuser-password
name: ${NAME}${SUFFIX}
- name: PATRONI_REPLICATION_USERNAME
valueFrom:
secretKeyRef:
key: replication-username
name: ${NAME}${SUFFIX}
- name: PATRONI_REPLICATION_PASSWORD
valueFrom:
secretKeyRef:
key: replication-password
name: ${NAME}${SUFFIX}
- name: APP_USER
valueFrom:
secretKeyRef:
key: app-db-username
name: ${NAME}${SUFFIX}
- name: APP_PASSWORD
valueFrom:
secretKeyRef:
key: app-db-password
name: ${NAME}${SUFFIX}
- name: APP_DATABASE
valueFrom:
secretKeyRef:
key: app-db-name
name: ${NAME}${SUFFIX}
- name: PATRONI_SCOPE
value: ${NAME}${SUFFIX}
- name: PATRONI_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: PATRONI_LOG_LEVEL
value: WARNING
- name: PATRONI_POSTGRESQL_DATA_DIR
value: /home/postgres/pgdata/pgroot/data
- name: PATRONI_POSTGRESQL_PGPASS
value: /tmp/pgpass
- name: PATRONI_POSTGRESQL_LISTEN
value: 0.0.0.0:5432
- name: PATRONI_RESTAPI_LISTEN
value: 0.0.0.0:8008
image: ${IMAGE_REGISTRY}/${IMAGE_STREAM_NAMESPACE}/${IMAGE_STREAM_TAG}
# Because we are using image reference to a tag, we need to always pull the image otherwise
# we end up with outdated/out-of-sync image depending on the node where it is running
imagePullPolicy: Always
name: postgresql
ports:
- containerPort: 8008
protocol: TCP
- containerPort: 5432
protocol: TCP
resources:
requests:
cpu: ${CPU_REQUEST}
memory: ${MEMORY_REQUEST}
limits:
cpu: ${CPU_LIMIT}
memory: ${MEMORY_LIMIT}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
readinessProbe:
initialDelaySeconds: 5
timeoutSeconds: 5
failureThreshold: 4
exec:
command:
- /usr/share/scripts/patroni/health_check.sh
volumeMounts:
- mountPath: /home/postgres/pgdata
name: postgresql
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccountName: ${NAME}${SUFFIX}
terminationGracePeriodSeconds: 0
updateStrategy:
type: RollingUpdate
volumeClaimTemplates:
- metadata:
annotations:
volume.beta.kubernetes.io/storage-class: ${STORAGE_CLASS}
labels:
app: ${NAME}${SUFFIX}
name: postgresql
spec:
storageClassName: ${STORAGE_CLASS}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: ${PVC_SIZE}
# It doesn't seem to be used/needed - remote it?
#- apiVersion: v1
# kind: Endpoints
# metadata:
# labels:
# app: ${NAME}${SUFFIX}
# cluster-name: ${NAME}${SUFFIX}
# name: ${NAME}${SUFFIX}
# subsets: []
parameters:
- description: The name of the application for labelling all artifacts.
displayName: Application Name
name: NAME
value: patroni
- name: SUFFIX
description: A suffix appended to all artifact's name (NAME)
- name: REPLICAS
displayName: REPLICAS
description: The number of statefulSet replicas to use.
value: '3'
- description: Starting amount of CPU the container can use.
displayName: CPU REQUEST
name: CPU_REQUEST
value: '250m'
- description: Maximum amount of CPU the container can use.
displayName: CPU Limit
name: CPU_LIMIT
value: '1'
- description: Starting amount of memory the container can use.
displayName: Memory Request
name: MEMORY_REQUEST
value: 512Mi
- description: Maximum amount of memory the container can use.
displayName: Memory Limit
name: MEMORY_LIMIT
value: 512Mi
- description: The OpenShift Namespace where the patroni and postgresql ImageStream
resides.
displayName: ImageStream Namespace
name: IMAGE_STREAM_NAMESPACE
value: "bcgov"
- name: IMAGE_STREAM_TAG
description: Patroni ImageTag
value: patroni:v11-stable
- description: The size of the persistent volume to create.
displayName: Persistent Volume Size
name: PVC_SIZE
value: 1Gi
- name: STORAGE_CLASS
value: netapp-block-standard
- name: IMAGE_REGISTRY
#ocp3#docker-registry.default.svc:5000
value: image-registry.openshift-image-registry.svc:5000