python3.5编译安装
yum install gcc
yum install openssl openssl-devel
yum install sqlite-devel
tar -zxvf Python-3.5.2.tgz
cd Python-3.5.2/
./configure --prefix=/opt/python
make && make install
pip3.6 install jupyterhub
/opt/python/bin/pip3.5 install jupyterhub
yum install npm nodejs-legacy
npm install -g configurable-http-proxy
/opt/python/bin/pip3.5 install notebook
useradd zhoull
passwd zhoull
yum install git
/opt/python/bin/pip3 install git+https://github.com/jupyterhub/kubespawner.git
配置k8s文件
import os
c.JupyterHub.spawner_class = 'kubespawner.KubeSpawner'
c.JupyterHub.ip = '0.0.0.0'
c.JupyterHub.hub_ip = '0.0.0.0'
# Don't try to cleanup servers on exit - since in general for k8s, we want
# the hub to be able to restart without losing user containers
c.JupyterHub.cleanup_servers = False
# First pulls can be really slow, so let's give it a big timeout
c.KubeSpawner.start_timeout = 60 * 5
# Our simplest user image! Optimized to just... start, and be small!
c.KubeSpawner.singleuser_image_spec = 'docker.io/jupyterhub/singleuser:0.8'
c.KubeSpawner.namespace='kube-system'
# The spawned containers need to be able to talk to the hub through the proxy!
c.KubeSpawner.hub_connect_ip = '192.168.10.30'
c.JupyterHub.hub_connect_ip = '192.168.10.30'
c.KubeSpawner.singleuser_service_account = 'default'
# Do not use any authentication at all - any username / password will work.
#c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
c.KubeSpawner.user_storage_pvc_ensure = False
c.JupyterHub.allow_named_servers = True
配置docker
import os
import pwd
c = get_config()
pjoin = os.path.join
#path of system
runtime_dir = pjoin('/opt/juphub/')
# Port to public
c.JupyterHub.ip = '172.16.204.112'
c.JupyterHub.port = 8027
c.JupyterHub.confirm_no_ssl = True
# JupyterHub cookie secret and state db
c.JupyterHub.cookie_secret_file = pjoin(runtime_dir, 'jupyterhub_cookie_secret')
c.JupyterHub.db_url = pjoin(runtime_dir, 'jupyterhub.sqlite')
c.JupyterHub.cookie_max_age_days = 7
c.JupyterHub.cleanup_proxy = True
c.JupyterHub.cleanup_servers = True
# put the log file in /var/log
c.JupyterHub.extra_log_file = pjoin(runtime_dir, 'log/jupyterhub.log')
c.JupyterHub.debug_proxy=True
#c.JupyterHub.logo_file=pjoin(runtime_dir, 'img/logo.png')
# Debug area
c.Application.log_level = "DEBUG"
c.JupyterHub.debug_db = True
c.JupyterHub.debug_proxy = True
# Purge and reset the database.
c.JupyterHub.reset_db = True
# Prefix to use for all metrics sent by jupyterhub to statsd
c.JupyterHub.statsd_prefix = 'utfsm'
# Principal users
c.Authenticator.whitelist = whitelist = set()
c.Authenticator.admin_users = admin = set()
with open(pjoin(runtime_dir, 'userlist')) as f:
for line in f:
if not line:
continue
parts = line.split()
name = parts[0]
whitelist.add(name)
if len(parts) > 1 and parts[1] == 'admin':
admin.add(name)
# Access for admin from list
c.JupyterHub.admin_access = True
# The docker instances need access to the Hub, so the default loopback port doesn't work:
c.JupyterHub.hub_ip = '172.16.204.112'
c.Spawner.default_url = '/lab'
# Spawn single-user servers as Docker containers3
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
#c.JupyterHub.spawner_class = 'dockerspawner.SystemUserSpawner'
#c.DockerSpawner.container_ip="172.16.204.125"
# For debugging arguments passed to spawned containers
c.DockerSpawner.debug = True
# Extras
#c.DockerSpawner.extra_host_config = {'mem_limit': '1G','memswap_limit': '1G'}
# Remove containers once they are stopped
c.DockerSpawner.remove_containers = True
# Spawn user containers from this image
c.DockerSpawner.container_image = 'docker.io/jupyter/scipy-notebook'
# Have the Spawner override the Docker run command
c.DockerSpawner.extra_create_kwargs.update({
'command': '/usr/local/bin/start-singleuser.sh'
# 'command': '/usr/local/bin/start.sh jupyter lab'
})
#c.DockerSpawner.read_only_volumes = {"/data/notebooks_lab": "/home/jovyan/work/"}
单机模式
c.JupyterHub.base_url = '/'
c.JupyterHub.hub_ip = '192.168.10.137'
c.JupyterHub.hub_port = 8082
c.JupyterHub.ip = '192.168.10.137'
c.JupyterHub.port = 8002
c.JupyterHub.proxy_api_ip = '192.168.10.137'
c.JupyterHub.proxy_api_port = 8003
c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
c.JupyterHub.statsd_prefix = 'jupyterhub'
c.Spawner.cmd=['jupyterhub-singleuser']
c.Authenticator.admin_users = {'zhoull'}
c.LocalAuthenticator.create_system_users = True
jupyterhub -f /opt/Python-3.6.0/jupyterhub_config.py
参考文档
https://github.com/jupyterhub/zero-to-jupyterhub-k8s
https://github.com/jupyterhub/dockerspawner
https://github.com/jupyterhub/kubespawner