Last active
May 19, 2020 11:42
-
-
Save yuvipanda/27e05d2f04455bb719aefdfac1954c81 to your computer and use it in GitHub Desktop.
tljh-dask-kubernetes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Set some environment variables\n", | |
"# These can be automated\n", | |
"import os\n", | |
"with open ('/etc/DIGITALOCEAN_ACCESS_TOKEN') as f:\n", | |
" os.environ['DIGITALOCEAN_ACCESS_TOKEN'] = f.read().strip().split(':')[-1]\n", | |
"\n", | |
"os.environ['KUBECONFIG'] = '/etc/kubeconfig'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"ERROR:root:Cannot add child handler, the child watcher does not have a loop attached\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "28b04ec75a0a480da6b45ed3dc9d3643", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"VBox(children=(HTML(value='<h2>KubeCluster</h2>'), HBox(children=(HTML(value='\\n<div>\\n <style scoped>\\n .…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"from dask_kubernetes import KubeCluster\n", | |
"from dask.distributed import Client\n", | |
"import dask.array as da# Connect Dask to the cluster\n", | |
"\n", | |
"cluster = KubeCluster()\n", | |
"cluster" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"client = Client(cluster)\n", | |
"cluster.scale(3)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1.0\n" | |
] | |
} | |
], | |
"source": [ | |
"array = da.ones((1000, 1000, 1000))\n", | |
"print(array.mean().compute()) # Should print 1.0\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment