Package: dask-k8
dask_k8Create Dask clusters in Kubernetes easily.The aim of this package is to be able to start a Dask client fromoutsideof a Kubernetes cluster
connecting to a Dask scheduler/workers runninginsideof a Kubernetes cluster.The dashboard of the dask scheduler running inside Kubernetes is accessible, the corresponding url is printed after the cluster creation.First ensure you have proper Kubernetes access, try runningkubectl get podsfor instance.Installationpip install dask_k8Example usagefromdask_k8importDaskCluster# Use a kubernetes namespace where you have the proper rights, the cluster_id is to distinguish between possible different clusterscluster=DaskCluster(namespace="dhlab",cluster_id="seguin-0")# Initialize clustercluster.create()# Get a dask.distributed.Clientdask_client=cluster.make_dask_client()# Increase/decrease the number of workerscluster.scale(40,blocking=True)# Will block until all the workers are effectively connected to the scheduler# Do the computationdask_client.compute(...)# IMPORTANT: Release the kubernetes resources, it is not done automaticallycluster.close()In order not to forget to release the resources, the following can be done:fromdask_k8importDaskClusterfromdask.diagnosticsimportprogressfromdask.distributedimportwaitcluster=DaskCluster(namespace="dhlab",cluster_id="seguin-0")withcluster:dask_client=cluster.make_dask_client()# Waits for the scheduler to be startedcluster.scale(40)# Waits for the workers to be started# Computedask_client.compute(...,sync=True)# Orfuture=dask_client.compute(...)progress(future)wait(future)The corresponding output is:Scheduler: tcp://10.90.47.7:31791
Dashboard: http://10.90.47.7:7062
Could not connect to scheduler, retrying...
Could not connect to scheduler, retrying...
Currently 0 workers out of the 40 required, waiting...
Currently 13 workers out of the 40 required, waiting...
Currently 21 workers out of the 40 required, waiting...
Currently 32 workers out of the 40 required, waiting...
Currently 33 workers out of the 40 required, waiting...
Currently 33 workers out of the 40 required, waiting...
Currently 34 workers out of the 40 required, waiting...
Reached the desired 40 workers!Specifying the workers/scheduler specificationsArbitrary pod specification can be given both for the scheduler and the worker.fromdask_k8importDaskClustercluster=DaskCluster(namespace="dhlab",cluster_id="seguin-0",worker_pod_spec="""containers:- image: daskdev/dask:latestargs: [dask-worker, $(DASK_SCHEDULER_ADDRESS), --nthreads, '1', --no-bokeh, --memory-limit, 4GB, --death-timeout, '60']imagePullPolicy: Alwaysname: dask-workerenv:- name: POD_IPvalueFrom:fieldRef:fieldPath: status.podIP- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: EXTRA_PIP_PACKAGESvalue: s3fs- name: EXTRA_CONDA_PACKAGESvalue:resources:requests:cpu: 1memory: "4G"limits:cpu: 1memory: "4G"""")How does it work?Kubernetes services are started to connect the dask scheduler and its dashboard to the outside of the Kubernetes cluster. They can be seen
withkubectl get svcwhenDaskClusteris running (after calling.create()).Two Kubernetes deployments are created, one for the scheduler and one for the workers. They can be seen withkubectl get deployments.The corresponding pods are automatically managed by Kubernetes and their states can be seen withkubectl get pods.ProjectThe 'impresso - Media Monitoring of the Past' project is funded by the Swiss National Science Foundation (SNSF) under grant numberCRSII5_173719(Sinergia program). The project aims at developing tools to process and explore large-scale collections of historical newspapers, and at studying the impact of this new tooling on historical research practices. More information athttps://impresso-project.ch.LicenseCopyright (C) 2020  Theimpressoteam. Contributors to this program include:Benoit Seguin.This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See theGNU Affero General Public Licensefor more details.