What Is JupyterHub? Components and Zero to JupyterHub on Kubernetes (2021 Notes)
Introduction
Section titled “Introduction”This is a record of a 2021 configuration and its observations, not a current production runbook. The stable/latest links are not pinned to that historical version. Before reuse, verify the authenticator, package compatibility, per-user storage, and actual single-user startup path.
JupyterHub is a practical way to provide Jupyter Notebook environments to multiple users. It acts as a multi-user control plane that creates and manages many single-user notebook servers while also handling proxying and authentication.
- It is composed of four main subsystems.
- A Hub that provides the user-facing control UI and coordinates the other subsystems
- An HTTP proxy that handles requests from the client browser
- A Spawner that manages multiple single-user Jupyter notebook servers
- An Authentication class that controls how users log in
Original figure: JupyterHub documentation (linked only, not embedded for licensing reasons)
See Jupyter Hub Docs https://jupyterhub.readthedocs.io/en/stable/index.html
Jupyter Hub for kubernetes Project
Section titled “Jupyter Hub for kubernetes Project”The JupyterHub for Kubernetes project makes it possible to deploy a self-managed JupyterHub on an existing Kubernetes environment, whether in the cloud or on-premises, and scale it for larger user groups. It is vendor-neutral and distributed as a Helm chart. (historical documented requirements: Kubernetes >= 1.14 / Helm >= 2.16; check the selected chart for current requirements)
- Architecture
- The services for handling user requests such as Proxy, Hub, etc. are the same
- A built-in Puller for pulling administrator-designated Docker Images and an Idle Culler for Resource management

- Main features
- Configure the hub, single-user servers, proxy, and related settings through the
config.yamlused for Helm deployment - Synchronize content from Git with
nbgitpuller - Let users manage their own conda kernels when needed
- Define a
profileListto offer different environments such as images, GPU options, and volumes - Choose an environment from
profileList. With chart 0.11.1 settinghub.allowNamedServers: false, each user has one default server; this is not a universal JupyterHub limit - Create each notebook server pod with the user’s identity
- Configure the hub, single-user servers, proxy, and related settings through the
See Jupyter Hub for kubernetes Docs https://zero-to-jupyterhub.readthedocs.io/en/stable/index.html
See Jupyter Hub KubeSpawner Docs https://jupyterhub-kubespawner.readthedocs.io/en/latest/spawner.html
- Manage JupyterHub for Kubernetes with
helm installandhelm upgrade - Environment
- k8s v1.19.7
- helm v3.5.2
- JupyterHub Helm chart v0.11.1
| Component | Version/evidence in this record |
|---|---|
| Kubernetes | 1.19.7 |
| Helm | 3.5.2 |
| JupyterHub Helm chart | 0.11.1 (helm upgrade --version=0.11.1) |
| JupyterHub package in the notebook image | The official-image Dockerfile excerpt below specifies 1.3.0; the actual Hub and custom-image package versions require separate verification |
See Install Jupyter Hub https://zero-to-jupyterhub.readthedocs.io/en/stable/jupyterhub/installation.html
- Historical
helm upgradeobservations (the command below is an archival deployment example, not executed for this revision)- Restarts the hub and proxy pods (
strategy.type: Recreate), typically within about one minute - New users cannot log in during the restart
- Existing users cannot start new login sessions during the restart
- Existing users cannot create new notebook files while the control plane is unavailable
- Users who already have notebooks open can continue working in notebooks that are already running.
- Restarts the hub and proxy pods (
The interruption scope and duration depend on Hub/proxy restarts, existing connections, and notebook-server state. The user behavior listed above is an observation from that environment, not a guarantee for every upgrade.
helm upgrade --cleanup-on-fail \--install $RELEASE jupyterhub/jupyterhub \--namespace $NAMESPACE \--create-namespace \--version=0.11.1 \--values config.yaml- Deployment details
$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGEhub 1/1 1 1 11dproxy 1/1 1 1 11duser-scheduler 2/2 2 2 11d
$ kubectl get dsNAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGEcontinuous-image-puller 2 2 2 2 2 <none> 11d
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEhub ClusterIP 10.0.0.10 <none> 8081/TCP 11dproxy-api ClusterIP 10.0.0.11 <none> 8001/TCP 11dproxy-public LoadBalancer 10.0.0.12 <EXTERNAL-IP> 443:31151/TCP,80:30780/TCP 11dHub with Notebook Official Image
Section titled “Hub with Notebook Official Image”Use the singleuser section in config.yaml to define a default profile based on the official Jupyter notebook image.
- Basic description of the Jupyter Notebook Official Image Dockerfile
- Based on the ubuntu base image, install the conda and python development environment
- Build the working environment in the home directory of the jovyan user
- Install notebook, jupyterhub, jupyterlab by default
- Run a separate shell script included in the Image to start the container
...
RUN conda install --quiet --yes \ 'notebook=6.3.0' \ 'jupyterhub=1.3.0' \ 'jupyterlab=3.0.14' && \ conda clean --all -f -y && \ npm cache clean --force && \ jupyter notebook --generate-config && \ jupyter lab clean && \ rm -rf /home/$NB_USER/.cache/yarn && \ fix-permissions $CONDA_DIR && \ fix-permissions /home/$NB_USER
...- config.yaml composition
- Set the default image in singleuser
- Through profileList, you can set administrator-designated images per profile
- Override the k8s settings in kubespawner to separately manage image / resource / volume, etc.
singleuser: image: name: jupyter/minimal-notebook tag: latest storage: type: none cpu: limit: 0.5 guarantee: 0.05 memory: limit: 1G guarantee: 256M
profileList: - display_name: "Minimal environment" description: "Default env." default: true - display_name: "Data Science environment" description: "Data Science env." kubespawner_override: # Official Image for Data Science image: jupyter/datascience-notebook:latest # Resources cpu_limit: 1 cpu_guarantee: 0.05 mem_limit: 2G mem_guarantee: 256M # Volumes volume_mounts: - name: jupyter-notebook-tf mountPath: /home/jovyan volumes: - name: jupyter-notebook-tf persistentVolumeClaim: claimName: jupyter-notebook-tfHere, singleuser.storage.type: none creates no per-user PVC for the default profile. Files in the container writable layer do not survive pod replacement. The fixed claimName: jupyter-notebook-tf in the Data Science and custom profiles shares one PVC without per-user claims or subPath. Mounting the entire /home/jovyan or /root does not guarantee file isolation. Concurrent mounting depends on access mode, node placement, and storage backend; RWO alone does not imply that it always fails. For production, design per-user PVCs and file permissions, and treat shared data volumes as a separate permission boundary.
- View the Jupyter Hub Profile List

Hub with Notebook Custom Image
Section titled “Hub with Notebook Custom Image”If you want to run a custom notebook image instead of the official image, the following checks are important.
- Install the jupyterhub package
- When JupyterHub creates the Notebook Server Pod, it runs via the jupyterhub-singleuser command installed in the Notebook Image.
- The Official Image has the jupyterhub package built in, so the Notebook can be run in Jupyter Hub without separate configuration changes.
- Since jupyterhub-singleuser can be run by installing the jupyterhub package, the jupyterhub package must be installed in the custom image.
- Custom Notebook Image Dockerfile (historical excerpt of the pre-migration root-based image, not a redeployment recipe)
-
Based on the ubuntu base image, assume python3 is installed and jupyter notebook / lab is installed.
-
Install and pin a Hub-compatible jupyterhub package at image build time. The Dockerfile below is a pre-migration excerpt, not the final image with that installation step.
-
Dockerfile
-
FROM ubuntu:18.04
USER root
RUN apt-get updateRUN apt-get install -y python3 python3-pip openjdk-8-jre wgetRUN ln -s /usr/bin/python3 /usr/bin/pythonRUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN python -m pip install --upgrade pipRUN python -m pip install notebook -U && pip install jupyterlab
RUN jupyter notebook --generate-config --allow-root -y
COPY run.sh /usr/local/bin/
EXPOSE 8888
WORKDIR /root- command run.sh (separating the pre-migration problem from Hub startup)
# The old script started a standalone server as root with an empty Notebook token.# That unauthenticated exposure path is intentionally omitted from this runnable example.# Install a compatible jupyterhub package at image build time,# then use this entrypoint only with the environment supplied by the Hub.exec jupyterhub-singleuser "$@"- Check runtime privileges when migrating an existing root-based image
- In the case of the Official Image, a common user named jovyan is created to run the Notebook Server, and no separate option needs to be specified even when running the jupyterhub-singleuser command.
- Change the securityContext settings through the uid / gid settings.
- The
uid: 0,gid: 0, and--allow-rootsettings below record historical migration compatibility, not production defaults. Migrate to a non-root image with matching UID/GID and home-volume permissions; do not mix Hub-authenticatedjupyterhub-singleuserstartup with a standalone Notebook server.
- config.yaml
- Modify kubespawner_override
...
- display_name: "Custom Notebook without conda" description: "without conda" kubespawner_override: cpu_limit: 1 cpu_guarantee: 0.1 mem_limit: 2G mem_guarantee: 512M # Historical root migration settings; not recommended for production uid: 0 gid: 0 cmd: ["jupyterhub-singleuser", "--allow-root", "--ip=0.0.0.0"] image: registry.example.invalid/jupyter-notebook-custom:latest image_pull_policy: Always volume_mounts: - name: jupyter-notebook-tf mountPath: /root volumes: - name: jupyter-notebook-tf persistentVolumeClaim: claimName: jupyter-notebook-tf
...Customization
Section titled “Customization”This section covers the customization work required during migration.
The goal is to reuse an existing Notebook or JupyterLab development container as faithfully as possible inside JupyterHub. The assumption here is that the existing runtime environment has been captured as an image with docker commit and will then be launched from JupyterHub.
Running a Docker Commit Image
Section titled “Running a Docker Commit Image”- Work order
- Create a Notebook development environment deployed to Kubernetes with the Custom Image
- Connect to the Worker Node where the Container is running
- Find the relevant Container ID and docker commit
- Push to the docker registry to complete the Migration Image
See docker commit of a Pod running on Kubernetes https://stackoverflow.com/questions/49481849/is-there-a-way-to-download-the-container-image-from-a-pod-in-kuberentes-environm
ENTRYPOINT Initialization
Section titled “ENTRYPOINT Initialization”- When Jupyter Hub creates the Notebook Server Pod, it runs the command defined in the args below to create it, and by default only the ip-allow / port-specify options are added.
Args: jupyterhub-singleuser --ip=0.0.0.0 --port=8888- If an initial execution script is defined in the command in the existing k8s deployment, that script runs and it becomes impossible to create the jupyterhub-singleuser notebook server.
containers: - image: registry.example.invalid/jupyter-notebook-custom:latest name: jupyter-notebook-custom imagePullPolicy: Always ports: - containerPort: 8888 # initial execution script command: ["/bin/sh", "-c", "run.sh"]- During Docker Commit, you need to initialize the ENTRYPOINT, or modify the script so that run.sh runs jupyterhub-singleuser
$ docker commit --change='ENTRYPOINT [""]' <container-id> jupyter-notebook-customJupyter Lab Compatibility
Section titled “Jupyter Lab Compatibility”Jupyter Lab
Section titled “Jupyter Lab”Jupyter Lab is the next-generation web-based user interface for Project Jupyter. Using Jupyter Lab, you can use Jupyter Notebook, Text Editor, Terminal, etc. in a flexible, integrated, and extensible way.
See Jupyter Lab Docs https://jupyterlab.readthedocs.io/en/latest/index.html
Compatibility
Section titled “Compatibility”- Running Lab in JupyterHub
- The official Jupyter notebook images already include the
jupyterlabpackage, so both the classic Notebook UI and JupyterLab are available immediately. - If a custom notebook image also installs
jupyterlab, it can expose the JupyterLab interface as well. - You can switch interfaces through the URL path:
domain:port/treedomain:port/lab
- With
kubespawner_override, each profile can set its owndefault_urland choose a different landing interface. - The migration checklist is otherwise the same as for a classic notebook image.
- The official Jupyter notebook images already include the
- display_name: "Bonjour Lab" description: "Bonjour tensorflow." kubespawner_override: cpu_limit: 1 cpu_guarantee: 0.1 # set Jupyter Lab as the initial landing screen,,, default_url: /lab mem_limit: 4G mem_guarantee: 512M image: registry.example.invalid/jupyter-notebook:bonjourIdle Culler
Section titled “Idle Culler”JupyterHub uses the jupyterhub-idle-culler service to identify and shut down idle or long-running notebook servers. Through JupyterHub API token authentication, it can also be run as a standalone Python script.
export JUPYTERHUB_API_TOKEN=$(jupyterhub token)python3 -m jupyterhub-idle-culler [--timeout=900] [--url=http://localhost:8081/hub/api]See Jupyter Hub Idel Culler Github Repository https://github.com/jupyterhub/jupyterhub-idle-culler
Main features
Section titled “Main features”- During the timeout setting period, user pods with no activity can be automatically deleted.
- In the historical test, an open browser connection kept the pod from being culled. Actual behavior depends on server activity reporting, connections, culler options, and versions.
- Restarting the server loses in-memory variables. Packages installed in the container writable layer are lost on pod replacement, unlike packages baked into the image and files on a retained PVC. Reusing an environment installed on a PVC requires checking mounts and paths.
Culling Test Result
Section titled “Culling Test Result”These are observations from the historical configuration, not tests re-run for this revision.
- cull: timeout: 120, every: 10 (seconds)
cull: enabled: true timeout: 120 every: 10- While the notebook screen is open, the pod is maintained
- Even if the notebook screen does not have focus, the pod is maintained
- The pod is killed only when you close the notebook screen and completely leave it
Authentication
Section titled “Authentication”Authenticator configuration and chart defaults
Section titled “Authenticator configuration and chart defaults”Defaults reference: chart 0.11.1 values.
The arbitrary-ID login observed here belongs to chart 0.11.1 default hub.config.JupyterHub.authenticator_class: dummy. The base Authenticator defines shared authentication/authorization settings; arbitrary-ID login is not the default behavior of every authentication class. Check the selected chart values and final Hub JupyterHub.authenticator_class.
JupyterHub includes an admin role with elevated privileges. Admins can start and stop other users’ servers and can optionally access those notebook servers directly. The control panel exposes an admin button that opens the admin panel for these operations.
DummyAuthenticatoris not a per-user password store. Admin/allowlist settings do not replace identity verification; credentials are validated by the chosen authenticator or identity provider.
- Jupyter Hub Admin Panel

Authenticator Use Case
Section titled “Authenticator Use Case”-
DummyAuthenticator without a password (restricted testing only)
- You can log in even by entering an arbitrary id, and a hub user is created with that id.
-
When admin user is set
- The Admin Panel can only be accessed when logging in with an id registered in admin_users
- The admin can add/edit/delete users and access/start/stop user servers
- In the passwordless dummy test, regular users can also log in with an arbitrary ID; this does not prove identity
-
When whitelist user is set
- Only ids registered in allowed_users can log in
- The admin can add whitelist users using the “Add Users” function in the Admin Panel
-
Data Repository
- The Hub DB PVC is separate from user notebook PVCs. Retention after
helm uninstalldepends on chart-template ownership/retention policies and whether the PVC is deleted; PV/data handling after PVC deletion depends on the StorageClass/PVreclaimPolicy. Uninstall behavior was not verified here. - Managing data with sqlite is the default setting.
- The Hub DB PVC is separate from user notebook PVCs. Retention after
-
Rest API
- Provides an API for managing user/server information per Jupyter Hub
- API calls are possible based on the API token issued by Jupyter Hub https://jupyterhub.readthedocs.io/en/latest/_static/rest-api/index.html
-
User Config Example
hub: config: JupyterHub: authenticator_class: "dummy" Authenticator: admin_users: - admin - user1 - user2 allowed_users: - user3 - user4DummyAuthenticator
Section titled “DummyAuthenticator”DummyAuthenticator can use one shared password but does not verify each user’s identity. The example below is only for restricted tests without external exposure; production authentication requires a separate identity-provider design, such as OAuthenticator.
- DummyAuthenticator password config
hub: config: Authenticator: admin_users: - admin - user1 - user2 allowed_users: - user3 - user4 DummyAuthenticator: password: <password> JupyterHub: authenticator_class: "dummy"OAuthenticator
Section titled “OAuthenticator”JupyterHub’s oauthenticator lets users authenticate through third-party OAuth2 identity providers such as GitHub, Google, and CILogon. An OAuth2 client ID and secret are required.
See Jupyter Hub oauthenticator Docs https://oauthenticator.readthedocs.io/en/stable/getting-started.html
Keycloak server authentication test with the GenericOAuthenticator class
Section titled “Keycloak server authentication test with the GenericOAuthenticator class”The HTTP IdP URLs and /auth path below record the Keycloak 12.0.4 configuration. For production, verify TLS termination, certificate validation on Hub-to-IdP connections, current Keycloak endpoints, OAuthenticator versions, and organization-access policies. Creating an OAuth app alone does not guarantee organization-member restrictions.
Keycloak supports both OpenID Connect and SAML 2.0, so it is a practical choice for SSO integration and for federating with third-party identity providers through OAuth2/OpenID Connect.
See KeyCloak Official Docs https://www.keycloak.org/docs/latest/getting_started/index.html#securing-a-sample-application
-
Environment
- k8s v1.19.7
- helm v3.5.2
- JupyterHub Helm chart v0.11.1
- keycloak v12.0.4
-
Test Architecture
- Work order
- Deploy the KeyCloak server to the kubernetes cluster using a helm chart
See codecentric/keycloak github https://github.com/codecentric/helm-charts/tree/master/charts/keycloak
- Deployment details
$ kubectl get all -n keycloak
NAME READY STATUS RESTARTSpod/keycloak-0 1/1 Running 0pod/keycloak-postgresql-0 1/1 Running 0
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)service/keycloak-headless ClusterIP None <none> 80/TCPservice/keycloak-http LoadBalancer 10.0.0.13 <external-ip> 80:30339/TCP,8443:32239/TCP,9990:30459/TCPservice/keycloak-postgresql ClusterIP 10.0.0.14 <none> 5432/TCPservice/keycloak-postgresql-headless ClusterIP None <none> 5432/TCP
NAME READYstatefulset.apps/keycloak 1/1statefulset.apps/keycloak-postgresql 1/1-
Configure a dedicated KeyCloak Realm / Client for Jupyter Hub

-
Add the keycloak app. to the Github Organization Oauth Apps

-
Using the Client ID/secret created above, add GitHub to the KeyCloak Identity Provider

-
Update the Authorization Callback URL in the Github Organization Oauth Apps, keycloak app.

-
Configure the GenericOAuthenticator in the Jupyter Hub config.yaml
: KeyCloak openid connect
hub: config: Authenticator: auto_login: true GenericOAuthenticator: admin_users: - admin client_id: <keycloak-client-id> client_secret: <keycloak-client-secret> # jupyter hub oauth callback oauth_callback_url: https://<jupyterhub-domain>/hub/oauth_callback # below are the keycloak auth / token / userdata URLs authorize_url: http://<keycloak-domain>/auth/realms/example-realm/protocol/openid-connect/auth token_url: http://<keycloak-domain>/auth/realms/example-realm/protocol/openid-connect/token userdata_url: http://<keycloak-domain>/auth/realms/example-realm/protocol/openid-connect/userinfo login_service: keycloak username_key: preferred_username userdata_params: state: state JupyterHub: authenticator_class: generic-oauthTest Result Summary
Section titled “Test Result Summary”-
On JupyterHub login, redirect to the Keycloak login page
- Can log in as a keycloak user
- Can log in via GitHub, the identity provider

-
Log in through GitHub registered as an identity provider in Keycloak
- In that historical configuration, only users in the relevant GitHub organization were observed to be authorized. Verify the organization restriction separately in the current deployment.

- In that historical configuration, only users in the relevant GitHub organization were observed to be authorized. Verify the organization restriction separately in the current deployment.
-
Notes : When using the JupyterHub logout function, only the JupyterHub session is deleted. | Logging out from JupyterHub does not automatically clear the Keycloak session or the upstream identity-provider session (SSO, GitHub, and so on). If you want logout to terminate every authenticated session in the chain, additional customization is required.