-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathclusterdefinition.yaml
399 lines (399 loc) · 14.8 KB
/
clusterdefinition.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
name: postgresql
labels:
{{- include "postgresql.labels" . | nindent 4 }}
spec:
type: postgresql
connectionCredential:
username: postgres
password: "$(RANDOM_PASSWD)"
endpoint: "$(SVC_FQDN):$(SVC_PORT_tcp-postgresql)"
host: "$(SVC_FQDN)"
port: "$(SVC_PORT_tcp-postgresql)"
componentDefs:
- name: postgresql
workloadType: Replication
characterType: postgresql
customLabelSpecs:
- key: apps.kubeblocks.postgres.patroni/scope
value: "$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)-patroni$(KB_CLUSTER_UID_POSTFIX_8)"
resources:
- gvk: "v1/Pod"
selector:
app.kubernetes.io/managed-by: kubeblocks
- gvk: "apps/v1/StatefulSet"
selector:
app.kubernetes.io/managed-by: kubeblocks
probes:
roleProbe:
failureThreshold: 2
periodSeconds: 1
timeoutSeconds: 1
monitor:
builtIn: false
exporterConfig:
scrapePath: /metrics
scrapePort: {{ .Values.metrics.service.port }}
logConfigs:
{{- range $name,$pattern := .Values.logConfigs }}
- name: {{ $name }}
filePathPattern: {{ $pattern }}
{{- end }}
configSpecs:
- name: postgresql-configuration
templateRef: postgresql-configuration
constraintRef: postgresql14-cc
keys:
- postgresql.conf
namespace: {{ .Release.Namespace }}
volumeName: postgresql-config
defaultMode: 0444
- name: pgbouncer-configuration
templateRef: pgbouncer-configuration
keys:
- pgbouncer.ini
namespace: {{ .Release.Namespace }}
volumeName: pgbouncer-config
defaultMode: 0444
- name: postgresql-custom-metrics
templateRef: postgresql14-custom-metrics
namespace: {{ .Release.Namespace }}
volumeName: postgresql-custom-metrics
defaultMode: 0444
- name: agamotto-configuration
templateRef: postgresql-agamotto-configuration
namespace: {{ .Release.Namespace }}
volumeName: agamotto-configuration
defaultMode: 0444
scriptSpecs:
- name: postgresql-scripts
templateRef: postgresql-scripts
namespace: {{ .Release.Namespace }}
volumeName: scripts
defaultMode: 0555
service:
ports:
- name: tcp-postgresql
port: 5432
targetPort: tcp-postgresql
- name: tcp-pgbouncer
port: 6432
targetPort: tcp-pgbouncer
volumeTypes:
- name: data
type: data
switchoverSpec:
withCandidate:
cmdExecutorConfig:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ default .Values.image.tags.major14.minor072 }}
command:
- /bin/bash
- -c
args:
- curl -s http://$(KB_REPLICATION_PRIMARY_POD_FQDN):8008/switchover -XPOST -d '{"leader":"$(KB_REPLICATION_PRIMARY_POD_NAME)","candidate":"$(KB_SWITCHOVER_CANDIDATE_NAME)"}'
withoutCandidate:
cmdExecutorConfig:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ default .Values.image.tags.major14.minor072 }}
command:
- /bin/bash
- -c
args:
- curl -s http://$(KB_REPLICATION_PRIMARY_POD_FQDN):8008/switchover -XPOST -d '{"leader":"$(KB_REPLICATION_PRIMARY_POD_NAME)"}'
podSpec:
securityContext:
runAsUser: 0
fsGroup: 103
runAsGroup: 103
fsGroupChangePolicy: OnRootMismatch
initContainers:
- name: pg-init-container
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
command:
- /kb-scripts/init_container.sh
volumeMounts:
- name: data
mountPath: {{ .Values.dataMountPath }}
- name: postgresql-config
mountPath: /home/postgres/conf
- name: scripts
mountPath: /kb-scripts
- name: pod-info
mountPath: /kb-podinfo
containers:
- name: postgresql
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
securityContext:
runAsUser: 0
command:
- /kb-scripts/setup.sh
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
exec:
command:
- /bin/sh
- -c
- -ee
- |
exec pg_isready -U {{ default "postgres" | quote }} -h 127.0.0.1 -p 5432
[ -f /postgresql/tmp/.initialized ] || [ -f /postgresql/.initialized ]
volumeMounts:
- name: dshm
mountPath: /dev/shm
- name: data
mountPath: {{ .Values.dataMountPath }}
- name: postgresql-config
mountPath: /home/postgres/conf
- name: scripts
mountPath: /kb-scripts
- name: pod-info
mountPath: /kb-podinfo
ports:
- name: tcp-postgresql
containerPort: 5432
- name: patroni
containerPort: 8008
env: ## refer https://github.com/zalando/spilo/blob/master/ENVIRONMENT.rst
- name: SERVICE_PORT
value: "5432"
- name: DCS_ENABLE_KUBERNETES_API
value: "true"
- name: KUBERNETES_USE_CONFIGMAPS
value: "true"
- name: SCOPE
value: "$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)-patroni$(KB_CLUSTER_UID_POSTFIX_8)"
- name: KUBERNETES_SCOPE_LABEL
value: "apps.kubeblocks.postgres.patroni/scope"
- name: KUBERNETES_ROLE_LABEL
value: "apps.kubeblocks.postgres.patroni/role"
- name: KUBERNETES_LABELS
value: '{"app.kubernetes.io/instance":"$(KB_CLUSTER_NAME)","apps.kubeblocks.io/component-name":"$(KB_COMP_NAME)"}'
- name: RESTORE_DATA_DIR
value: {{ .Values.dataMountPath }}/kb_restore
- name: KB_PG_CONFIG_PATH
value: /home/postgres/conf/postgresql.conf
- name: SPILO_CONFIGURATION
value: | ## https://github.com/zalando/patroni#yaml-configuration
bootstrap:
initdb:
- auth-host: md5
- auth-local: trust
- name: ALLOW_NOSSL
value: "true"
- name: PGROOT
value: {{ .Values.dataMountPath }}/pgroot
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: PGUSER_SUPERUSER
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: username
optional: false
- name: PGPASSWORD_SUPERUSER
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: PGUSER_ADMIN
value: superadmin
- name: PGPASSWORD_ADMIN
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: PGUSER_STANDBY
value: standby
- name: PGPASSWORD_STANDBY
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: PGUSER
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: username
optional: false
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: pgbouncer
image: {{ .Values.pgbouncer.image.registry | default .Values.image.registry }}/{{ .Values.pgbouncer.image.repository }}:{{ default .Values.pgbouncer.image.tag }}
imagePullPolicy: {{ .Values.pgbouncer.image.pullPolicy | quote }}
securityContext:
runAsUser: 0
ports:
- name: tcp-pgbouncer
containerPort: 6432
volumeMounts:
- name: pgbouncer-config
mountPath: /home/pgbouncer/conf
- name: scripts
mountPath: /kb-scripts
command:
- /kb-scripts/pgbouncer_setup.sh
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 15
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
tcpSocket:
port: tcp-pgbouncer
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 15
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
tcpSocket:
port: tcp-pgbouncer
env:
- name: PGBOUNCER_AUTH_TYPE
value: md5
- name: POSTGRESQL_USERNAME
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: username
optional: false
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: POSTGRESQL_PORT
value: "5432"
- name: POSTGRESQL_HOST
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: PGBOUNCER_PORT
value: "6432"
- name: PGBOUNCER_BIND_ADDRESS
value: "0.0.0.0"
- name: metrics
image: {{ .Values.metrics.image.registry | default .Values.image.registry }}/{{ .Values.metrics.image.repository }}:{{ .Values.metrics.image.tag }}
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
securityContext:
runAsUser: 0
env:
- name: ENDPOINT
value: {{ printf "127.0.0.1:5432" }}
- name: DATA_SOURCE_PASS
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: DATA_SOURCE_USER
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: username
optional: false
command:
- "/bin/agamotto"
- "--config=/opt/agamotto/agamotto-config.yaml"
ports:
- name: http-metrics
containerPort: {{ .Values.metrics.service.port }}
volumeMounts:
- name: postgresql-custom-metrics
mountPath: /opt/conf
- name: agamotto-configuration
mountPath: /opt/agamotto
volumes:
- name: dshm
emptyDir:
medium: Memory
{{- with .Values.shmVolume.sizeLimit }}
sizeLimit: {{ . }}
{{- end }}
- name: pod-info
downwardAPI:
items:
- path: "pod-role"
fieldRef:
fieldPath: metadata.labels['kubeblocks.io/role']
- path: "primary-pod"
fieldRef:
fieldPath: metadata.annotations['rs.apps.kubeblocks.io/primary']
- path: "component-replicas"
fieldRef:
fieldPath: metadata.annotations['apps.kubeblocks.io/component-replicas']
systemAccounts:
cmdExecutorConfig:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ default .Values.image.tags.major14.minor072 }}
command:
- psql
args:
- -h$(KB_ACCOUNT_ENDPOINT)
- -c
- $(KB_ACCOUNT_STATEMENT)
env:
- name: PGUSER
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: username
optional: false
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
passwordConfig:
length: 10
numDigits: 5
numSymbols: 0
letterCase: MixedCases
accounts:
- name: kbadmin
provisionPolicy: &kbAdminAcctRef
type: CreateByStmt
scope: AnyPods
statements:
creation: CREATE USER $(USERNAME) SUPERUSER PASSWORD '$(PASSWD)';
update: ALTER USER $(USERNAME) WITH PASSWORD '$(PASSWD)';
- name: kbdataprotection
provisionPolicy: *kbAdminAcctRef
- name: kbprobe
provisionPolicy: &kbReadonlyAcctRef
type: CreateByStmt
scope: AnyPods
statements:
creation: CREATE USER $(USERNAME) WITH PASSWORD '$(PASSWD)'; GRANT pg_monitor TO $(USERNAME);
update: ALTER USER $(USERNAME) WITH PASSWORD '$(PASSWD)';
- name: kbmonitoring
provisionPolicy: *kbReadonlyAcctRef
- name: kbreplicator
provisionPolicy:
type: CreateByStmt
scope: AnyPods
statements:
creation: CREATE USER $(USERNAME) WITH REPLICATION PASSWORD '$(PASSWD)';
update: ALTER USER $(USERNAME) WITH PASSWORD '$(PASSWD)';