Kubernetes已经Release 1.17.0,直接使用kubeadm建立高可用集群成为现实。这里咱们将进一步快速建立并设置JupyterHub for K8s。因为Helm在2019年已经大幅度更新,安装方法也有比较大的区别。如下详述具体步骤。html
helm是一个模版化的k8s服务安装系统,其版本参考以下:python
获取helm步骤以下:linux
wget https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz tar -vxf helm-v3.0.2-linux-amd64.tar.gz sudo cp linux-amd64/helm /usr/local/bin/
添加repo的命令以下:git
helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/ helm repo update输出:
Hang tight while we grab the latest from your chart repositories... ...Skip local chart repository ...Successfully got an update from the "stable" chart repository ...Successfully got an update from the "jupyterhub" chart repository Update Complete. ⎈ Happy Helming!⎈
建立一个 32 bytes的随机数用做security token.。运行下面的命令并复制输出结果:github
openssl rand -hex 32
建立并编辑文件 config.yaml。
使用 nano editor, 也可使用其它的。shell
nano config.yaml
将上面的token复制到 config.yaml
文件中,替代 <RANDOM-HEX>
这一部份内容。json
proxy: secretToken: "<RANDOM_HEX>"
安装chart,使用配置文件 config.yaml
。以下:api
# Suggested values: advanced users of Kubernetes and Helm should feel # free to use different values. RELEASE=jhub NAMESPACE=jhub helm upgrade --install $RELEASE jupyterhub/jupyterhub \ --namespace $NAMESPACE \ --version=0.8.2 \ --values config.yaml
查看pod,咱们将jupyterhub安装到了jhub命名空间中。浏览器
kubectl get pod --namespace jhub
注意:bash
建议 enable autocompletion for kubectl 并设置 --namespace
flag:
kubectl config set-context $(kubectl config current-context) --namespace ${NAMESPACE:-jhub}
缺省安装使用LoadBalancer提供对外服务。
找到JupyterHub的服务IP。
运行下面的命令,直到 EXTERNAL-IP
of the proxy-public
service 可用。
kubectl get service --namespace jhub获得:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hub ClusterIP 10.51.243.14 <none> 8081/TCP 1m proxy-api ClusterIP 10.51.247.198 <none> 8001/TCP 1m proxy-public LoadBalancer 10.51.248.230 104.196.41.97 80:31916/TCP 1m
注意:
这里 IP for proxy-public
若是显示太长,考虑使用:
kubectl describe service proxy-public --namespace jhub
为了使用 JupyterHub,输入 external IP for the proxy-public
到浏览器地址栏。缺省状况下,可使用任何的username and password 组合进入。
也可使用Proxy或NodePort来提供外部访问(参考 Kubernetes 1.17.0管理界面Dashboard 2 的设置方法)。
注意:若是升级到最近的python3版本,JupyterHub运行时出现错误,Notebook Server没法启动,进pod日志发现提示信息"NoneType",能够采用下面的方法修复:
kubectl patch deploy -n jhub hub --type json \ --patch '[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["bash", "-c", "\nmkdir -p ~/hotfix\ncp \ -r /usr/local/lib/python3.6/dist-packages/kubespawner ~/hotfix\nls -R ~/hotfix\npatch ~/hotfix/kubespawner/spawner.py \ << EOT\n72c72\n< key=lambda x: x.last_timestamp,\n---\n> key=lambda x: x.last_timestamp and x.last_timestamp.timestamp() or 0.,\nEOT\n\nPYTHONPATH=$HOME/hotfix \ jupyterhub --config /srv/jupyterhub_config.py --upgrade-db\n"]}]'
再去访问JupyterHub的服务,恢复正常。