JupyterHub
JupyterHub - решение для многопользовательских сред.
- HTTP-proxy, осуществляющий маршрутизацию запросов пользователей
- HUB, который осуществляет аутентификацию пользователей (с помощью Authenticator) и управление индивидуальными jupyter-notebook (с помощью Spawners)
При входе пользователя для него создается Pod (с именем jupyter-username), в котором и будет работать пользователь. Для этого pod'а создается PersistentVolumeClaim, соотвественно нужен PersistentVolume.
https://z2jh.jupyter.org/en/latest/setup-jupyterhub/setup-jupyterhub.html
https://hub.docker.com/r/jupyterhub/k8s-hub/tags
https://zero-to-jupyterhub.readthedocs.io/en/latest/administrator/authentication.html
https://ipython-books.github.io/36-introducing-jupyterlab/
kubectl create ns jhub helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/ helm repo update echo -e "proxy:\n secretToken: '`openssl rand -hex 32`'" > ./jhub_config.yaml helm upgrade --install jhub jupyterhub/jupyterhub --namespace jhub --version=0.9.0-beta.2 --values jhub_config.yaml
jhub_pvs.yaml
apiVersion: v1 kind: PersistentVolume metadata: name: hub-db-dir-pv namespace: jhub labels: app: jupyterhub component: hub spec: capacity: storage: 20Gi accessModes: - ReadWriteOnce hostPath: path: "/kubernetes_volumes/jhub/hub-db-dir-pv" type: Directory persistentVolumeReclaimPolicy: Retain --- apiVersion: v1 kind: PersistentVolume metadata: name: jhub-admin-pv namespace: jhub labels: app: jupyterhub component: singleuser-server spec: capacity: storage: 20Gi accessModes: - ReadWriteOnce hostPath: path: "/kubernetes_volumes/jhub/jhub-admin-pv" type: Directory persistentVolumeReclaimPolicy: Retain
Ошибки текущей стабильной версии 0.8.2
Exception in Future <Task finished coro=<BaseHandler.spawn_single_user.<locals>.finish_user_spawn() done, defined at /usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/base.py:629> exception=TypeError("'<' not supported between instances of 'datetime.datetime' and 'NoneType'",)> after timeout
Такая ошибка возникает, если запускать версию 0.8.2 в кластере kubernetes версии выше, чем 0.14. Решение для версии 0.8.2 можно найти тут: https://github.com/jupyterhub/kubespawner/issues/354
Либо можно обновить jhub до более новой версии :
helm upgrade jhub jupyterhub/jupyterhub --namespace jhub --version=0.9.0-beta.2
Jupyter Notebook on kubernetes
Как выбрать подходящий docker-image: https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html
Я буду разворачивать jupyter/scipy-notebook.
jupyter_deployment.yaml
kind: Namespace
apiVersion: v1
metadata:
name: jupyter-notebook
labels:
name: jupyter-notebook
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jupyter-notebook
namespace: jupyter-notebook
spec:
replicas: 1
selector:
matchLabels:
app: jupyter-notebook
template:
metadata:
labels:
app: jupyter-notebook
spec:
containers:
- name: jupyter-notebook
image: jupyter/scipy-notebook:latest
---
apiVersion: v1
kind: Service
metadata:
name: jupyter-notebook-http
namespace: jupyter-notebook
spec:
selector:
app: jupyter-notebook
type: ClusterIP
ports:
- name: http
port: 8888
protocol: TCP
targetPort: 8888
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
name: jupyter-notebook-ingress
namespace: jupyter-notebook
spec:
rules:
- host: jpn.autosys.tk
http:
paths:
- backend:
serviceName: jupyter-notebook-http
servicePort: 8888
path: /
tls:
- hosts:
- jpn.autosys.tk
secretName: jpn-autosys-tk-tls
Discussion