jupyterhub docker k8s

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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Docker中配置JupyterHub,您可以按照以下步骤进行操作: 1. 首先,确保您已经安装了DockerDocker Compose。如果没有,请先安装它们。 2. 创建一个名为`jupyterhub`的文件夹,并在其中创建一个名为`Dockerfile`的文件。 3. 在`Dockerfile`中添加以下内容: ```Dockerfile FROM jupyterhub/jupyterhub:1.4 # 安装 JupyterHub 的依赖包 RUN pip install jupyterhub-dummyauthenticator # 添加自定义配置文件 COPY jupyterhub_config.py /srv/jupyterhub/jupyterhub_config.py ``` 这个Dockerfile基于官方的JupyterHub镜像,并安装了一个名为`jupyterhub-dummyauthenticator`的虚拟认证器,以便在测试环境中使用。您可以根据需要更改认证器。 4. 在`jupyterhub`文件夹中创建一个名为`jupyterhub_config.py`的文件,并添加您的JupyterHub配置。例如: ```python c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator' c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner' .DockerSpawner.image = 'jupyter/scipy-notebook' c.DockerSpawner.remove_containers = True # 添加其他配置选项... ``` 这里使用了`dummyauthenticator`作为虚拟认证器,并使用了`dockerspawner`作为启动器。您可以根据需要添加其他配置选项。 5. 确保您在`jupyterhub`文件夹中有一个名为`jupyterhub_config.py`的配置文件和一个名为`Dockerfile`的Docker文件。 6. 打开终端,导航到`jupyterhub`文件夹,并构建Docker镜像: ``` docker build -t jupyterhub-image . ``` 这会构建一个名为`jupyterhub-image`的Docker镜像。 7. 创建一个名为`docker-compose.yml`的文件,并添加以下内容: ```yaml version: '3' services: jupyterhub: image: jupyterhub-image ports: - 8000:8000 volumes: - /var/run/docker.sock:/var/run/docker.sock ``` 这个`docker-compose.yml`文件定义了一个名为`jupyterhub`的服务,使用之前构建的Docker镜像,并将主机的8000端口映射到容器的8000端口。 8. 在终端中导航到包含`docker-compose.yml`文件的目录,并运行以下命令启动JupyterHub: ``` docker-compose up -d ``` 现在,您应该可以通过访问`http://localhost:8000`来访问JupyterHub。 请注意,这只是一个简单的示例配置。根据您的需求,您可能需要进行更多的配置和调整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值