This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16.9k
/
statefulset.yaml
372 lines (372 loc) · 15.3 KB
/
statefulset.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
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "rabbitmq.fullname" . }}
labels:
app: {{ template "rabbitmq.name" . }}
chart: {{ template "rabbitmq.chart" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
serviceName: {{ template "rabbitmq.fullname" . }}-headless
podManagementPolicy: {{ .Values.podManagementPolicy }}
replicas: {{ .Values.replicas }}
updateStrategy:
type: {{ .Values.updateStrategy.type }}
{{- if (eq "Recreate" .Values.updateStrategy.type) }}
rollingUpdate: null
{{- end }}
selector:
matchLabels:
app: {{ template "rabbitmq.name" . }}
release: "{{ .Release.Name }}"
template:
metadata:
labels:
app: {{ template "rabbitmq.name" . }}
release: "{{ .Release.Name }}"
chart: {{ template "rabbitmq.chart" . }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
annotations:
{{- if or (not .Values.rabbitmq.existingErlangSecret) (not .Values.rabbitmq.existingPasswordSecret) }}
checksum/secret: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
spec:
{{- if .Values.schedulerName }}
schedulerName: "{{ .Values.schedulerName }}"
{{- end }}
{{- include "rabbitmq.imagePullSecrets" . | indent 6 }}
{{- if .Values.rbacEnabled}}
serviceAccountName: {{ template "rabbitmq.fullname" . }}
{{- end }}
{{- if .Values.affinity }}
affinity: {{- include "rabbitmq.tplValue" (dict "value" .Values.affinity "context" .) | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
terminationGracePeriodSeconds: 10
{{- if and .Values.volumePermissions.enabled .Values.persistence.enabled .Values.securityContext.enabled }}
initContainers:
- name: volume-permissions
image: "{{ template "rabbitmq.volumePermissions.image" . }}"
imagePullPolicy: {{ default "" .Values.volumePermissions.image.pullPolicy | quote }}
command: ["/bin/chown", "-R", "{{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }}", "{{ .Values.persistence.path }}"]
securityContext:
runAsUser: 0
resources:
{{ toYaml .Values.volumePermissions.resources | indent 10 }}
volumeMounts:
- name: data
mountPath: "{{ .Values.persistence.path }}"
{{- end }}
containers:
- name: rabbitmq
image: {{ template "rabbitmq.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
command:
- bash
- -ec
- |
mkdir -p /opt/bitnami/rabbitmq/.rabbitmq/
mkdir -p /opt/bitnami/rabbitmq/etc/rabbitmq/
touch /opt/bitnami/rabbitmq/var/lib/rabbitmq/.start
#persist the erlang cookie in both places for server and cli tools
echo $RABBITMQ_ERL_COOKIE > /opt/bitnami/rabbitmq/var/lib/rabbitmq/.erlang.cookie
cp /opt/bitnami/rabbitmq/var/lib/rabbitmq/.erlang.cookie /opt/bitnami/rabbitmq/.rabbitmq/
#change permission so only the user has access to the cookie file
chmod 600 /opt/bitnami/rabbitmq/.rabbitmq/.erlang.cookie /opt/bitnami/rabbitmq/var/lib/rabbitmq/.erlang.cookie
#copy the mounted configuration to both places
cp /opt/bitnami/rabbitmq/conf/* /opt/bitnami/rabbitmq/etc/rabbitmq
# Apply resources limits
{{- if .Values.rabbitmq.setUlimitNofiles }}
ulimit -n "${RABBITMQ_ULIMIT_NOFILES}"
{{- end }}
#replace the default password that is generated
sed -i "/CHANGEME/cdefault_pass=${RABBITMQ_PASSWORD//\\/\\\\}" /opt/bitnami/rabbitmq/etc/rabbitmq/rabbitmq.conf
{{- if and .Values.persistence.enabled .Values.forceBoot.enabled }}
if [ -d "{{ .Values.persistence.path }}/mnesia/${RABBITMQ_NODENAME}" ]; then rabbitmqctl force_boot; fi
{{- end }}
exec rabbitmq-server
{{- if .Values.resources }}
resources:
{{ toYaml .Values.resources | indent 10 }}
{{- end }}
volumeMounts:
- name: config-volume
mountPath: /opt/bitnami/rabbitmq/conf
- name: healthchecks
mountPath: /usr/local/sbin/rabbitmq-api-check
subPath: rabbitmq-api-check
- name: healthchecks
mountPath: /usr/local/sbin/rabbitmq-health-check
subPath: rabbitmq-health-check
{{- if .Values.rabbitmq.tls.enabled }}
- name: {{ template "rabbitmq.fullname" . }}-certs
mountPath: /opt/bitnami/rabbitmq/certs
{{- end }}
- name: data
mountPath: "{{ .Values.persistence.path }}"
{{- if .Values.rabbitmq.loadDefinition.enabled }}
- name: load-definition-volume
mountPath: /app
readOnly: true
{{- end }}
ports:
- name: epmd
containerPort: 4369
- name: amqp
containerPort: {{ .Values.service.port }}
{{- if .Values.rabbitmq.tls.enabled }}
- name: amqp-ssl
containerPort: {{ .Values.service.tlsPort }}
{{- end }}
- name: dist
containerPort: {{ .Values.service.distPort }}
- name: stats
containerPort: {{ .Values.service.managerPort }}
{{- if .Values.service.extraContainerPorts }}
{{ toYaml .Values.service.extraContainerPorts | indent 8 }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
exec:
command:
- sh
- -c
- rabbitmq-api-check "http://{{ .Values.rabbitmq.username }}:$RABBITMQ_PASSWORD@127.0.0.1:{{ .Values.service.managerPort }}/api/healthchecks/node" '{"status":"ok"}'
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
exec:
command:
- sh
- -c
- rabbitmq-health-check "http://{{ .Values.rabbitmq.username }}:$RABBITMQ_PASSWORD@127.0.0.1:{{ .Values.service.managerPort }}/api/healthchecks/node" '{"status":"ok"}'
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
{{- end }}
{{- if and (gt (.Values.replicas | int) 1) ( eq .Values.rabbitmq.clustering.rebalance true) }}
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- until rabbitmqctl cluster_status >/dev/null; do echo Waiting for
cluster readiness...; sleep 5 ; done; rabbitmq-queues rebalance "all"
{{- end }}
env:
- name: BITNAMI_DEBUG
value: {{ ternary "true" "false" .Values.image.debug | quote }}
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: MY_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: K8S_SERVICE_NAME
value: "{{ template "rabbitmq.fullname" . }}-headless"
- name: K8S_ADDRESS_TYPE
value: {{ .Values.rabbitmq.clustering.address_type }}
{{- if (eq "hostname" .Values.rabbitmq.clustering.address_type) }}
- name: RABBITMQ_NODENAME
value: "rabbit@$(MY_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.{{ .Values.rabbitmq.clustering.k8s_domain }}"
- name: K8S_HOSTNAME_SUFFIX
value: ".$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.{{ .Values.rabbitmq.clustering.k8s_domain }}"
{{- else }}
- name: RABBITMQ_NODENAME
{{- if .Values.rabbitmq.rabbitmqClusterNodeName }}
value: {{ .Values.rabbitmq.rabbitmqClusterNodeName | quote }}
{{- else }}
value: "rabbit@$(MY_POD_NAME)"
{{- end }}
{{- end }}
{{- if .Values.ldap.enabled }}
- name: RABBITMQ_LDAP_ENABLE
value: "yes"
- name: RABBITMQ_LDAP_TLS
value: {{ ternary "yes" "no" .Values.ldap.tls.enabled | quote }}
- name: RABBITMQ_LDAP_SERVER
value: {{ .Values.ldap.server }}
- name: RABBITMQ_LDAP_SERVER_PORT
value: {{ .Values.ldap.port | quote }}
- name: RABBITMQ_LDAP_USER_DN_PATTERN
value: {{ .Values.ldap.user_dn_pattern }}
{{- end }}
- name: RABBITMQ_LOGS
value: {{ .Values.rabbitmq.logs | quote }}
- name: RABBITMQ_ULIMIT_NOFILES
value: {{ .Values.rabbitmq.ulimitNofiles | quote }}
{{- if and .Values.rabbitmq.maxAvailableSchedulers }}
- name: RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS
value: {{ printf "+S %s:%s" (toString .Values.rabbitmq.maxAvailableSchedulers) (toString .Values.rabbitmq.onlineSchedulers) -}}
{{- end }}
- name: RABBITMQ_USE_LONGNAME
value: "true"
- name: RABBITMQ_ERL_COOKIE
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq.secretErlangName" . }}
key: rabbitmq-erlang-cookie
- name: RABBITMQ_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq.secretPasswordName" . }}
key: rabbitmq-password
{{- range $key, $value := .Values.rabbitmq.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.metrics.enabled }}
- name: metrics
image: {{ template "rabbitmq.metrics.image" . }}
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
env:
- name: RABBIT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq.secretPasswordName" . }}
key: rabbitmq-password
- name: RABBIT_URL
value: "http://{{ .Values.metrics.rabbitmqAddress }}:{{ .Values.service.managerPort }}"
- name: RABBIT_USER
value: {{ .Values.rabbitmq.username }}
- name: PUBLISH_PORT
value: "{{ .Values.metrics.port }}"
{{ if .Values.metrics.capabilities }}
- name: RABBIT_CAPABILITIES
value: "{{ .Values.metrics.capabilities }}"
{{- end }}
{{- range $key, $value := .Values.metrics.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
ports:
- name: metrics
containerPort: {{ .Values.metrics.port }}
{{- if .Values.metrics.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /metrics
port: metrics
initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }}
periodSeconds: {{ .Values.metrics.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.metrics.livenessProbe.failureThreshold }}
successThreshold: {{ .Values.metrics.livenessProbe.successThreshold }}
{{- end }}
{{- if .Values.metrics.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /metrics
port: metrics
initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }}
timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }}
periodSeconds: {{ .Values.metrics.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.metrics.readinessProbe.failureThreshold }}
successThreshold: {{ .Values.metrics.readinessProbe.successThreshold }}
{{- end }}
resources:
{{ toYaml .Values.metrics.resources | indent 10 }}
{{- end }}
{{- if .Values.securityContext.enabled }}
securityContext:
fsGroup: {{ .Values.securityContext.fsGroup }}
runAsUser: {{ .Values.securityContext.runAsUser }}
{{- if .Values.securityContext.extra }}
{{- toYaml .Values.securityContext.extra | nindent 8 }}
{{- end }}
{{- end }}
volumes:
{{- if .Values.rabbitmq.tls.enabled }}
- name: {{ template "rabbitmq.fullname" . }}-certs
secret:
secretName: {{ if .Values.rabbitmq.tls.existingSecret }}{{ .Values.rabbitmq.tls.existingSecret }}{{- else }}{{ template "rabbitmq.fullname" . }}-certs{{- end }}
items:
- key: ca.crt
path: ca_certificate.pem
- key: tls.crt
path: server_certificate.pem
- key: tls.key
path: server_key.pem
{{- end }}
- name: config-volume
configMap:
name: {{ template "rabbitmq.fullname" . }}-config
items:
- key: rabbitmq.conf
path: rabbitmq.conf
{{- if .Values.rabbitmq.advancedConfiguration}}
- key: advanced.config
path: advanced.config
{{- end }}
- key: enabled_plugins
path: enabled_plugins
- name: healthchecks
configMap:
name: {{ template "rabbitmq.fullname" . }}-healthchecks
items:
- key: rabbitmq-health-check
path: rabbitmq-health-check
mode: 111
- key: rabbitmq-api-check
path: rabbitmq-api-check
mode: 111
{{- if .Values.rabbitmq.loadDefinition.enabled }}
- name: load-definition-volume
secret:
secretName: {{ .Values.rabbitmq.loadDefinition.secretName | quote }}
{{- end }}
{{- if not .Values.persistence.enabled }}
- name: data
emptyDir: {}
{{- else if .Values.persistence.existingClaim }}
- name: data
persistentVolumeClaim:
{{- with .Values.persistence.existingClaim }}
claimName: {{ tpl . $ }}
{{- end }}
{{- else }}
volumeClaimTemplates:
- metadata:
name: data
labels:
app: {{ template "rabbitmq.name" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{ include "rabbitmq.storageClass" . }}
{{- end }}