-
Notifications
You must be signed in to change notification settings - Fork 52
/
rabbitmq-cluster-template.yaml
252 lines (240 loc) · 6.67 KB
/
rabbitmq-cluster-template.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
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: rabbitmq-cluster
annotations:
description: "Deploys a RabbitMQ cluster"
iconClass: icon-rabbitmq
tags: rabbitmq,mq,messaging
parameters:
- name: NAMESPACE
description: "OpenShift project (current namespace)"
required: true
- name: CLUSTER_NAME
description: "Name of the RabbitMQ cluster"
value: rabbitmq-cluster
- name: ISTAG
description: "Image to deploy"
value: rabbitmq:3.8-management
- name: RABBITMQ_USER
description: "Username for the RabbitMQ instance"
value: rabbitmq
- name: RABBITMQ_PASS
description: "Password securing the RabbitMQ instance"
generate: expression
from: "[a-zA-Z0-9]{16}"
- name: ERLANG_COOKIE
description: "Cookie used for authentication of cluster nodes"
generate: expression
from: "[a-zA-Z0-9]{16}"
- name: SERVICE_ACCOUNT
description: "Name of the service account used by RabbitMQ k8s plugin"
value: rabbitmq-discovery
- name: VOLUME_SIZE
description: "Size of the RabbitMQ data volume"
value: 1Gi
objects:
# This service account is needed for rabbit_peer_discovery_k8s plugin to be able to discover
# cluster nodes
- apiVersion: v1
kind: ServiceAccount
metadata:
name: ${SERVICE_ACCOUNT}
- apiVersion: v1
kind: RoleBinding
metadata:
name: ${SERVICE_ACCOUNT}-view
roleRef:
kind: Role
name: view
subjects:
- kind: ServiceAccount
name: ${SERVICE_ACCOUNT}
- apiVersion: v1
kind: Secret
stringData:
username: ${RABBITMQ_USER}
password: ${RABBITMQ_PASS}
url: "amqp://${RABBITMQ_USER}:${RABBITMQ_PASS}@${CLUSTER_NAME}-balancer"
cookie: ${ERLANG_COOKIE}
metadata:
name: ${CLUSTER_NAME}-secret
type: Opaque
- apiVersion: v1
kind: ConfigMap
metadata:
name: ${CLUSTER_NAME}-config
data:
rabbitmq.conf: |
loopback_users.guest = false
## Clustering
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
cluster_formation.k8s.address_type = hostname
cluster_formation.k8s.service_name = ${CLUSTER_NAME}
cluster_formation.k8s.hostname_suffix = .${CLUSTER_NAME}.${NAMESPACE}.svc.cluster.local
cluster_formation.node_cleanup.interval = 10
cluster_formation.node_cleanup.only_log_warning = true
cluster_partition_handling = autoheal
## queue master locator
queue_master_locator=min-masters
enabled_plugins: |
[rabbitmq_management,rabbitmq_peer_discovery_k8s].
# Load balancer
- kind: Service
apiVersion: v1
metadata:
name: ${CLUSTER_NAME}-balancer
labels:
app: ${CLUSTER_NAME}
type: LoadBalancer
spec:
type: ClusterIP
ports:
- name: http
protocol: TCP
port: 15672
targetPort: 15672
- name: amqp
protocol: TCP
port: 5672
targetPort: 5672
selector:
app: ${CLUSTER_NAME}
# Headless service that makes it possible to lookup individual rabbitmq nodes
- apiVersion: v1
kind: Service
metadata:
name: ${CLUSTER_NAME}
labels:
app: ${CLUSTER_NAME}
spec:
selector:
app: ${CLUSTER_NAME}
clusterIP: None
ports:
- name: amqp
port: 5672
targetPort: 5672
- name: clustering
port: 25672
targetPort: 25672
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: ${CLUSTER_NAME}-internal-access
spec:
podSelector:
matchLabels:
app: ${CLUSTER_NAME}
ingress:
- from:
- podSelector:
matchLabels:
app: ${CLUSTER_NAME}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: ${CLUSTER_NAME}
labels:
app: ${CLUSTER_NAME}
spec:
serviceName: ${CLUSTER_NAME}
replicas: 2
selector:
matchLabels:
app: ${CLUSTER_NAME}
template:
metadata:
labels:
app: ${CLUSTER_NAME}
spec:
serviceAccountName: ${SERVICE_ACCOUNT}
terminationGracePeriodSeconds: 30
containers:
- name: rabbitmq
command:
- sh
args:
- -c
- cp -v /etc/rabbitmq/rabbitmq.conf ${RABBITMQ_CONFIG_FILE}.conf; exec docker-entrypoint.sh rabbitmq-server
image: ${ISTAG}
imagePullPolicy: IfNotPresent
volumeMounts:
- name: config-volume
mountPath: /etc/rabbitmq
- name: rabbitmq-storage
mountPath: /var/lib/rabbitmq
ports:
- name: http
protocol: TCP
containerPort: 15672
- name: amqp
protocol: TCP
containerPort: 5672
- name: clustering
protocol: TCP
containerPort: 25672
livenessProbe:
exec:
command: ["rabbitmqctl", "status"]
initialDelaySeconds: 30
timeoutSeconds: 10
readinessProbe:
exec:
command: ["rabbitmqctl", "status"]
initialDelaySeconds: 10
timeoutSeconds: 10
env:
- name: RABBITMQ_DEFAULT_USER
valueFrom:
secretKeyRef:
name: ${CLUSTER_NAME}-secret
key: username
- name: RABBITMQ_DEFAULT_PASS
valueFrom:
secretKeyRef:
name: ${CLUSTER_NAME}-secret
key: password
- name: RABBITMQ_ERLANG_COOKIE
valueFrom:
secretKeyRef:
name: ${CLUSTER_NAME}-secret
key: cookie
- name: K8S_SERVICE_NAME
value: ${CLUSTER_NAME}
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: RABBITMQ_USE_LONGNAME
value: "true"
- name: RABBITMQ_NODENAME
value: "rabbit@$(POD_NAME).${CLUSTER_NAME}.$(POD_NAMESPACE).svc.cluster.local"
- name: RABBITMQ_CONFIG_FILE
value: /var/lib/rabbitmq/rabbitmq
volumes:
- name: config-volume
configMap:
name: ${CLUSTER_NAME}-config
items:
- key: rabbitmq.conf
path: rabbitmq.conf
- key: enabled_plugins
path: enabled_plugins
volumeClaimTemplates:
- metadata:
name: rabbitmq-storage
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: ${VOLUME_SIZE}