-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspark-template.yml
552 lines (510 loc) · 17.2 KB
/
spark-template.yml
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
apiVersion: template.openshift.io/v1
kind: Template
labels:
app: spark
template: spark
message: |-
The following components have been scheduled for creation in your project: Spark master, Spark master UI, Jupyter
Go to project overview -> once the creation of all the components are finished, use the following links -
To access Jupyter: ${CLUSTER_NAME}-jupyter.${APPLICATION_DOMAIN_SUFFIX}
To access Spark UI: ${CLUSTER_NAME}-spark.${APPLICATION_DOMAIN_SUFFIX}
metadata:
annotations:
description: Deploys Apache Spark cluster with Jupyter Notebook/Lab.
For more information regarding the usage of this setup (including information of different variables), see - https://github.com/CSCfi/spark-openshift
By default, the setup deploys a spark cluster with 4 Workers, 1 Master and 1 Jupyter pod. Spark code ran via Jupyter notebook/lab automatically runs on the cluster.
The configuration for the worker, master and jupyter pods can be changed according to the Openshift Quota(Limit Range).
To get more quota, you should contact Openshift admins.
WARNING- This deployment setup is still in the experimental stage.
iconClass: icon-hadoop
openshift.io/display-name: Apache Spark
openshift.io/documentation-url: https://github.com/CSCfi/spark-openshift
openshift.io/support-url: https://www.csc.fi/contact-info
openshift.io/long-description: Apache Spark is a popular framework for processing
large amounts of data, see - https://spark.apache.org
Jupyter is a web based application which allows you to write python code in a browser, see - https://jupyter.org
To learn more about Spark configurations, see - https://spark.apache.org/docs/latest/configuration.html
To learn Spark programming, see - https://spark.apache.org/docs/2.2.0/rdd-programming-guide.html
openshift.io/provider-display-name: CSC
tags: spark, jupyter, python
template.openshift.io/bindable: "false"
name: apache-spark
objects:
- apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
name: ${CLUSTER_NAME}-pvc
spec:
accessModes:
- "ReadWriteMany"
resources:
requests:
storage: ${STORAGE_SIZE}
- apiVersion: v1
kind: Secret
metadata:
name: ${CLUSTER_NAME}-secret
type: Opaque
stringData:
secret.env: |-
USER=${USERNAME}
PASS=${PASSWORD}
- apiVersion: v1
kind: ConfigMap
metadata:
name: ${CLUSTER_NAME}-nginx-config-spark
data:
default.conf: |
upstream node {
server localhost:8080;
}
server {
server_name _;
listen 9001;
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host ${CLUSTER_NAME}-spark.${APPLICATION_DOMAIN_SUFFIX};
proxy_pass http://node;
proxy_redirect off;
port_in_redirect off;
auth_basic "Spark UI Login";
auth_basic_user_file /etc/nginx/secrets/passwd;
}
}
- apiVersion: v1
kind: ConfigMap
metadata:
name: ${CLUSTER_NAME}-nginx-config-jupyter
data:
default.conf: |-
upstream node {
server localhost:8888;
}
client_max_body_size 0;
server {
server_name _;
listen 8080;
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host ${CLUSTER_NAME}-jupyter.${APPLICATION_DOMAIN_SUFFIX};
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
proxy_pass http://node;
proxy_redirect off;
port_in_redirect off;
auth_basic "Jupyter Login";
auth_basic_user_file /etc/nginx/secrets/passwd;
}
}
- apiVersion: v1
kind: ConfigMap
metadata:
name: ${CLUSTER_NAME}-jupyter-notebook-config
data:
notebook_config.py: |-
# Configuration file for ipython-notebook.
c = get_config()
# ------------------------------------------------------------------------------
# NotebookApp configuration
# ------------------------------------------------------------------------------
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.ip = '127.0.0.1'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.base_url = '/'
c.NotebookApp.trust_xheaders = True
c.NotebookApp.tornado_settings = {'static_url_prefix': '/static/'}
c.NotebookApp.notebook_dir = '/mnt/${CLUSTER_NAME}-pvc'
c.NotebookApp.allow_origin = '*'
c.NotebookApp.token = ''
c.NotebookApp.password = ''
c.NotebookApp.allow_remote_access = True
- apiVersion: v1
kind: Service
metadata:
name: ${CLUSTER_NAME}-spark-master
spec:
ports:
- port: 7077
targetPort: 7077
selector:
app: ${CLUSTER_NAME}-spark-master
- apiVersion: v1
kind: Service
metadata:
name: ${CLUSTER_NAME}-spark-master-ui
spec:
ports:
- port: 80
targetPort: 9001
selector:
app: ${CLUSTER_NAME}-spark-master
- apiVersion: v1
kind: Service
metadata:
name: ${CLUSTER_NAME}-jupyter-notebook
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: ${CLUSTER_NAME}-jupyter-notebook-service
selector:
app: ${CLUSTER_NAME}-jupyter-notebook
- apiVersion: v1
kind: Route
metadata:
name: ${CLUSTER_NAME}-spark-master-route
spec:
host: ${CLUSTER_NAME}-spark.${APPLICATION_DOMAIN_SUFFIX}
path: /
to:
kind: Service
name: ${CLUSTER_NAME}-spark-master-ui
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
- apiVersion: v1
kind: Route
metadata:
name: ${CLUSTER_NAME}-jupyter-notebook-route
spec:
host: ${CLUSTER_NAME}-jupyter.${APPLICATION_DOMAIN_SUFFIX}
path: /
to:
kind: Service
name: ${CLUSTER_NAME}-jupyter-notebook
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
description: Spark master
template.alpha.openshift.io/wait-for-ready: "true"
name: ${CLUSTER_NAME}-spark-master
spec:
replicas: 1
template:
metadata:
labels:
app: ${CLUSTER_NAME}-spark-master
spec:
volumes:
- name: ${CLUSTER_NAME}-nginx-config-vol
configMap:
name: ${CLUSTER_NAME}-nginx-config-spark
items:
- key: default.conf
path: default.conf
- name: ${CLUSTER_NAME}-secret-vol
secret:
secretName: ${CLUSTER_NAME}-secret
- name: ${CLUSTER_NAME}-htpasswd-vol
emptyDir: {}
- name: ${CLUSTER_NAME}-vol
persistentVolumeClaim:
claimName: ${CLUSTER_NAME}-pvc
initContainers:
- image: docker-registry.rahti.csc.fi/da-images/alpine-htpasswd:latest
command: ["/bin/sh","-c","source /tmp/secret-env/secret.env && htpasswd -bc /tmp/secret-file/passwd $USER $PASS"]
name: htpasswd-generator
volumeMounts:
- name: ${CLUSTER_NAME}-htpasswd-vol
mountPath: "/tmp/secret-file"
- name: ${CLUSTER_NAME}-secret-vol
mountPath: "/tmp/secret-env"
- name: busybox
image: docker-registry.rahti.csc.fi/da-images/busybox:1
args:
- "/bin/mkdir"
- "-p"
- "/mnt/${CLUSTER_NAME}-pvc/.tools/${CLUSTER_NAME}/master"
volumeMounts:
- name: ${CLUSTER_NAME}-vol
mountPath: /mnt/${CLUSTER_NAME}-pvc
containers:
- name: proxy-rewriter
image: docker-registry.rahti.csc.fi/spark-images/nginx:latest
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 300m
memory: 512Mi
ports:
- containerPort: 9001
volumeMounts:
- name: ${CLUSTER_NAME}-nginx-config-vol
mountPath: /opt/bitnami/nginx/conf/server_blocks
- name: ${CLUSTER_NAME}-htpasswd-vol
mountPath: /etc/nginx/secrets
- name: spark-master
image: ${MASTER_IMAGE}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7077
- containerPort: 8080
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 30
resources:
requests:
cpu: ${MASTER_CPU}
memory: ${MASTER_MEMORY}
limits:
cpu: ${MASTER_CPU}
memory: ${MASTER_MEMORY}
env:
- name: START_COMMAND
value: "/usr/local/bin/start-master.sh"
- name: SPARK_PUBLIC_DNS
value: ${CLUSTER_NAME}-spark.${APPLICATION_DOMAIN_SUFFIX}
- name: SPARK_RECOVERY_DIR
value: /mnt/${CLUSTER_NAME}-pvc/.tools/${CLUSTER_NAME}/master
volumeMounts:
- name: ${CLUSTER_NAME}-vol
mountPath: /mnt/${CLUSTER_NAME}-pvc
- apiVersion: v1
kind: DeploymentConfig
metadata:
name: ${CLUSTER_NAME}-spark-worker
spec:
replicas: ${WORKER_REPLICAS}
template:
metadata:
annotations:
description: Spark Worker
template.alpha.openshift.io/wait-for-ready: "true"
labels:
app: ${CLUSTER_NAME}-spark-worker
spec:
volumes:
- name: ${CLUSTER_NAME}-vol
persistentVolumeClaim:
claimName: ${CLUSTER_NAME}-pvc
containers:
- name: spark-worker
image: ${WORKER_IMAGE}
imagePullPolicy: IfNotPresent
env:
- name: SPARK_WORKER_MEMORY
value: "${WORKER_MEMORY}"
- name: SPARK_WORKER_CORES
value: "${WORKER_CPU}"
- name: SPARK_MASTER_SERVICE_HOST
value: ${CLUSTER_NAME}-spark-master
- name: SPARK_WORKER_DIRS
value: "/tmp/worker"
- name: START_COMMAND
value: "/usr/local/bin/start-worker.sh"
ports:
- containerPort: 8081
livenessProbe:
httpGet:
path: /
port: 8081
initialDelaySeconds: 30
timeoutSeconds: 30
resources:
requests:
cpu: ${WORKER_CPU}
memory: ${WORKER_MEMORY}
limits:
cpu: ${WORKER_CPU}
memory: ${WORKER_MEMORY}
volumeMounts:
- name: ${CLUSTER_NAME}-vol
mountPath: /mnt/${CLUSTER_NAME}-pvc
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
description: Spark jupyter notebook
template.alpha.openshift.io/wait-for-ready: "true"
name: ${CLUSTER_NAME}-jupyter-notebook
spec:
strategy:
type: Rolling
triggers:
- type: ConfigChange
replicas: 1
template:
metadata:
labels:
app: ${CLUSTER_NAME}-jupyter-notebook
spec:
volumes:
- name: ${CLUSTER_NAME}-nginx-config-vol
configMap:
name: ${CLUSTER_NAME}-nginx-config-jupyter
- name: ${CLUSTER_NAME}-secret-vol
secret:
secretName: ${CLUSTER_NAME}-secret
- name: ${CLUSTER_NAME}-htpasswd-vol
emptyDir: {}
- name: ${CLUSTER_NAME}-jupyter-notebook-config-vol
configMap:
name: ${CLUSTER_NAME}-jupyter-notebook-config
- name: ${CLUSTER_NAME}-vol
persistentVolumeClaim:
claimName: ${CLUSTER_NAME}-pvc
initContainers:
- image: docker-registry.rahti.csc.fi/da-images/alpine-htpasswd:latest
command: ["/bin/sh","-c","source /tmp/secret-env/secret.env && htpasswd -bc /tmp/secret-file/passwd $USER $PASS"]
name: htpasswd-generator
volumeMounts:
- name: ${CLUSTER_NAME}-htpasswd-vol
mountPath: "/tmp/secret-file"
- name: ${CLUSTER_NAME}-secret-vol
mountPath: "/tmp/secret-env"
containers:
- name: proxy-rewriter
image: docker-registry.rahti.csc.fi/spark-images/nginx:latest
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 300m
memory: 512Mi
ports:
- containerPort: 8080
volumeMounts:
- name: ${CLUSTER_NAME}-nginx-config-vol
mountPath: /opt/bitnami/nginx/conf/server_blocks
- name: ${CLUSTER_NAME}-htpasswd-vol
mountPath: /etc/nginx/secrets
- name: jupyter
image: ${JUPYTER_IMAGE}
imagePullPolicy: IfNotPresent
env:
- name: START_COMMAND
value: "/usr/local/bin/start-notebook.sh"
- name: JUPYTER_ENABLE_LAB
value: ${JUPYTER_ENABLE_LAB}
- name: SPARK_MASTER_SERVICE
value: spark://${CLUSTER_NAME}-spark-master:7077
- name: SPARK_OPTS
value: --master=spark://${CLUSTER_NAME}-spark-master:7077
- name: SPARK_DRIVER_MEMORY # Need to set these values according to allocated resources
value: ${DRIVER_MEMORY}
- name: SPARK_DRIVER_CORES
value: ${DRIVER_CPU}
- name: SPARK_EXECUTOR_CORES_DEFAULT
value: ${EXECUTOR_CORES_DEFAULT}
- name: SPARK_EXECUTOR_MEMORY_DEFAULT
value: ${EXECUTOR_MEMORY_DEFAULT}
resources:
requests:
cpu: ${DRIVER_CPU}
memory: ${DRIVER_MEMORY}
limits:
cpu: ${DRIVER_CPU}
memory: ${DRIVER_MEMORY}
ports:
- containerPort: 8888
volumeMounts:
- name: ${CLUSTER_NAME}-jupyter-notebook-config-vol
mountPath: /home/notebook/.jupyter/notebook_config.py
subPath: notebook_config.py
- name: ${CLUSTER_NAME}-vol
mountPath: /mnt/${CLUSTER_NAME}-pvc
parameters:
- description: Unique identifier for your cluster. Recommended value - your username
displayName: Cluster Name
name: CLUSTER_NAME
required: true
- description: Create a new username for logging into Spark UI and Jupyter
displayName: Username
name: USERNAME
required: true
- description: Create a new password for logging into Spark UI and Jupyter
displayName: Password
name: PASSWORD
required: true
- description: Number of Workers
displayName: Worker Replicas
name: WORKER_REPLICAS
required: true
value: '4'
- description: Persistent Storage Size
displayName: Storage Size
name: STORAGE_SIZE
required: true
value: '10Gi'
- description: Launch Jupyter Lab instead of Jupyter Notebook
displayName: Enable Jupyter Lab
name: JUPYTER_ENABLE_LAB
required: true
value: 'False'
- description: CPU for Master
displayName: Master CPU
name: MASTER_CPU
required: true
value: '1'
- description: Memory for Master
displayName: Master Memory
name: MASTER_MEMORY
required: true
value: 4G
- description: CPU for Worker
displayName: Worker CPU
name: WORKER_CPU
required: true
value: '2'
- description: Memory for Worker
displayName: Worker Memory
name: WORKER_MEMORY
required: true
value: 4G
- description: Default value for Spark Executor Cores
displayName: Executor Default Cores
name: EXECUTOR_CORES_DEFAULT
required: true
value: '2'
- description: Default value for Spark Executor Memory (Should always be less than the Worker memory!)
displayName: Executor Default Memory
name: EXECUTOR_MEMORY_DEFAULT
required: true
value: 3G
- description: CPU for Driver(Jupyter)
displayName: Driver CPU
name: DRIVER_CPU
required: true
value: '1'
- description: Memory for Driver(Jupyter)
displayName: Driver Memory
name: DRIVER_MEMORY
required: true
value: 4G
- description: Docker Image for the Master
displayName: Master Image
name: MASTER_IMAGE
required: true
value: docker-registry.rahti.csc.fi/spark-images/spark:2.4
- description: Docker Image for the Worker
displayName: Worker Image
name: WORKER_IMAGE
required: true
value: docker-registry.rahti.csc.fi/spark-images/spark:2.4
- description: Docker Image for the Jupyter (Driver)
displayName: Worker Image
name: JUPYTER_IMAGE
required: true
value: docker-registry.rahti.csc.fi/spark-images/spark:2.4
- description: The exposed hostname suffix that will be used to create routes for Spark UI and Jupyter Notebook
displayName: Application Hostname Suffix
name: APPLICATION_DOMAIN_SUFFIX
value: rahtiapp.fi