-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKubernetesCeleryExecutor.yaml
504 lines (492 loc) · 13.3 KB
/
KubernetesCeleryExecutor.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
apiVersion: v1
kind: Namespace
metadata:
name: airflow
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: airflow
spec:
type: NodePort
ports:
- name: mysql
port: 3306
targetPort: 3306
protocol: TCP
selector:
app: mysql
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: airflow
spec:
serviceName: "mysql"
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: email2liyang/mysql-for-airflow:5.7.24
volumeMounts:
- name: datadir
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: airflow
- name: MYSQL_USER
value: airflow
- name: MYSQL_PASSWORD
value: airflow
- name: MYSQL_DATABASE
value: airflow
ports:
- containerPort: 3306
# No pre-stop hook is required, a SIGTERM plus some time is all that's
# needed for graceful shutdown of a node.
terminationGracePeriodSeconds: 60
volumeClaimTemplates:
- metadata:
name: datadir
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: 1Gi
---
# from https://github.com/rabbitmq/rabbitmq-peer-discovery-k8s/blob/master/examples/k8s_statefulsets
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: rabbitmq
namespace: airflow
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: endpoint-reader
namespace: airflow
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: endpoint-reader
namespace: airflow
subjects:
- kind: ServiceAccount
name: rabbitmq
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: endpoint-reader
---
kind: Service
apiVersion: v1
metadata:
namespace: airflow
name: rabbitmq
labels:
app: rabbitmq
type: LoadBalancer
spec:
type: NodePort
ports:
- name: http
protocol: TCP
port: 15672
targetPort: 15672
nodePort: 31672
- name: amqp
protocol: TCP
port: 5672
targetPort: 5672
nodePort: 30672
selector:
app: rabbitmq
---
apiVersion: v1
kind: ConfigMap
metadata:
name: rabbitmq-config
namespace: airflow
data:
enabled_plugins: |
[rabbitmq_management,rabbitmq_peer_discovery_k8s].
rabbitmq.conf: |
## Cluster formation. See https://www.rabbitmq.com/cluster-formation.html to learn more.
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
## Should RabbitMQ node name be computed from the pod's hostname or IP address?
## IP addresses are not stable, so using [stable] hostnames is recommended when possible.
## Set to "hostname" to use pod hostnames.
## When this value is changed, so should the variable used to set the RABBITMQ_NODENAME
## environment variable.
cluster_formation.k8s.address_type = hostname
## How often should node cleanup checks run?
cluster_formation.node_cleanup.interval = 30
## Set to false if automatic removal of unknown/absent nodes
## is desired. This can be dangerous, see
## * https://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup
## * https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ
cluster_formation.node_cleanup.only_log_warning = true
cluster_partition_handling = autoheal
## See https://www.rabbitmq.com/ha.html#master-migration-data-locality
queue_master_locator=min-masters
## See https://www.rabbitmq.com/access-control.html#loopback-users
loopback_users.guest = false
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: rabbitmq
namespace: airflow
spec:
serviceName: rabbitmq
replicas: 1
template:
metadata:
labels:
app: rabbitmq
spec:
serviceAccountName: rabbitmq
terminationGracePeriodSeconds: 10
containers:
- name: rabbitmq-k8s
image: rabbitmq:3.7
volumeMounts:
- name: config-volume
mountPath: /etc/rabbitmq
- name: datadir
mountPath: /var/lib/rabbitmq
ports:
- name: http
protocol: TCP
containerPort: 15672
- name: amqp
protocol: TCP
containerPort: 5672
livenessProbe:
exec:
command: ["rabbitmqctl", "status"]
initialDelaySeconds: 60
# See https://www.rabbitmq.com/monitoring.html for monitoring frequency recommendations.
periodSeconds: 60
timeoutSeconds: 15
readinessProbe:
exec:
command: ["rabbitmqctl", "status"]
initialDelaySeconds: 20
periodSeconds: 60
timeoutSeconds: 10
imagePullPolicy: Always
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: RABBITMQ_USE_LONGNAME
value: "true"
# See a note on cluster_formation.k8s.address_type in the config file section
- name: RABBITMQ_NODENAME
value: "rabbit@$(MY_POD_NAME).rabbitmq.airflow.svc.cluster.local"
- name: K8S_SERVICE_NAME
value: "rabbitmq"
- name: K8S_HOSTNAME_SUFFIX
value: '.rabbitmq.airflow.svc.cluster.local'
- name: RABBITMQ_ERLANG_COOKIE
value: "mycookie"
volumes:
- name: config-volume
configMap:
name: rabbitmq-config
items:
- key: rabbitmq.conf
path: rabbitmq.conf
- key: enabled_plugins
path: enabled_plugins
volumeClaimTemplates:
- metadata:
name: datadir
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: 5Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: airflow-celery-webserver
namespace: airflow
spec:
replicas: 1
selector:
matchLabels:
app: airflow-celery-webserver
template:
metadata:
labels:
name: airflow-celery-webserver
app: airflow-celery-webserver
spec:
containers:
- name: airflow-celery-webserver
image: docker.io/email2liyang/docker-airflow:1.10.2
imagePullPolicy: Always
env:
- name: LOAD_EX
value: "y"
- name: EXECUTOR
value: Celery
- name: AIRFLOW_MYSQL_DB_HOST
value: mysql
- name: AIRFLOW_MYSQL_DB_PORT
value: "3306"
- name: FERNET_KEY
value: 46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
- name: AIRFLOW__CELERY__BROKER_URL
value: amqp://guest:guest@rabbitmq:5672
- name: AIRFLOW__CELERY__RESULT_BACKEND
value: db+mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
value: mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__EXECUTOR
value: CeleryExecutor
readinessProbe:
httpGet:
path: /admin/
port: 8080
initialDelaySeconds: 8
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /admin/
port: 8080
initialDelaySeconds: 8
timeoutSeconds: 10
ports:
- name: webserver
containerPort: 8080
command: ["/entrypoint.sh"]
args: ["webserver"]
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: airflow-celery-flower
namespace: airflow
spec:
replicas: 1
selector:
matchLabels:
app: airflow-celery-flower
template:
metadata:
labels:
name: airflow-celery-flower
app: airflow-celery-flower
spec:
containers:
- name: airflow-celery-flower
image: docker.io/email2liyang/docker-airflow:1.10.2
imagePullPolicy: Always
env:
- name: LOAD_EX
value: "y"
- name: EXECUTOR
value: Celery
- name: AIRFLOW_MYSQL_DB_HOST
value: mysql
- name: AIRFLOW_MYSQL_DB_PORT
value: "3306"
- name: FERNET_KEY
value: 46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
- name: AIRFLOW__CELERY__BROKER_URL
value: amqp://guest:guest@rabbitmq:5672
- name: AIRFLOW__CELERY__RESULT_BACKEND
value: db+mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
value: mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__EXECUTOR
value: CeleryExecutor
readinessProbe:
httpGet:
path: /
port: 5555
initialDelaySeconds: 8
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /
port: 5555
initialDelaySeconds: 8
timeoutSeconds: 10
ports:
- name: flower
containerPort: 5555
command: ["/entrypoint.sh"]
args: ["flower"]
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: airflow-celery-scheduler
namespace: airflow
spec:
replicas: 1
selector:
matchLabels:
app: airflow-celery-scheduler
template:
metadata:
labels:
name: airflow-celery-scheduler
app: airflow-celery-scheduler
spec:
containers:
- name: airflow-celery-scheduler
image: docker.io/email2liyang/docker-airflow:1.10.2
imagePullPolicy: Always
env:
- name: LOAD_EX
value: "y"
- name: EXECUTOR
value: Celery
- name: AIRFLOW_MYSQL_DB_HOST
value: mysql
- name: AIRFLOW_MYSQL_DB_PORT
value: "3306"
- name: FERNET_KEY
value: 46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
- name: AIRFLOW__CELERY__BROKER_URL
value: amqp://guest:guest@rabbitmq:5672
- name: AIRFLOW__CELERY__RESULT_BACKEND
value: db+mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
value: mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__EXECUTOR
value: CeleryExecutor
readinessProbe:
exec:
command:
- /bin/bash
- -c
- ps -ef | grep scheduler | grep -v "grep"
initialDelaySeconds: 8
timeoutSeconds: 10
livenessProbe:
exec:
command:
- /bin/bash
- -c
- ps -ef | grep scheduler | grep -v "grep"
initialDelaySeconds: 8
timeoutSeconds: 10
command: ["/entrypoint.sh"]
args: ["scheduler"]
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: airflow-celery-worker
namespace: airflow
spec:
replicas: 2
selector:
matchLabels:
app: airflow-celery-worker
template:
metadata:
labels:
name: airflow-celery-worker
app: airflow-celery-worker
spec:
containers:
- name: airflow-celery-worker
image: docker.io/email2liyang/docker-airflow:1.10.2
imagePullPolicy: Always
env:
- name: LOAD_EX
value: "y"
- name: EXECUTOR
value: Celery
- name: AIRFLOW_MYSQL_DB_HOST
value: mysql
- name: AIRFLOW_MYSQL_DB_PORT
value: "3306"
- name: FERNET_KEY
value: 46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
- name: AIRFLOW__CELERY__BROKER_URL
value: amqp://guest:guest@rabbitmq:5672
- name: AIRFLOW__CELERY__RESULT_BACKEND
value: db+mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
value: mysql://airflow:airflow@$(AIRFLOW_MYSQL_DB_HOST):$(AIRFLOW_MYSQL_DB_PORT)/airflow
- name: AIRFLOW__CORE__EXECUTOR
value: CeleryExecutor
readinessProbe:
exec:
command:
- /bin/bash
- -c
- ps -ef | grep celeryd | grep -v "grep"
initialDelaySeconds: 8
timeoutSeconds: 10
livenessProbe:
exec:
command:
- /bin/bash
- -c
- ps -ef | grep celeryd | grep -v "grep"
initialDelaySeconds: 8
timeoutSeconds: 10
command: ["/entrypoint.sh"]
args: ["worker"]
---
apiVersion: v1
kind: Service
metadata:
name: airflow-celery-webserver
namespace: airflow
spec:
type: NodePort
ports:
- name: webserver
port: 8080
targetPort: webserver
selector:
app: airflow-celery-webserver
---
apiVersion: v1
kind: Service
metadata:
name: airflow-celery-flower
namespace: airflow
spec:
type: NodePort
ports:
- name: flower
port: 5555
targetPort: flower
selector:
app: airflow-celery-flower