How to configure Jupyterhub to run code-server?

Do you have an example hub configuration to run single-user code-server instance? The only solution I found is not clear.

Is there any way to configure to select to launch Jupyterlab and/or code-server and/or R-Studio after the Jupyterhub login page?

As mentioned in nils-braun’s codehub project, using this, I can;

  • Let users choose between different “profiles” (e.g. resources, predefined images)
  • Customize user
  • Using a different authenticator, e.g. OAuth2 (e.g. via GitHub), LDAP, Active Directory.
  • Use HTTPS for encrypting the communication with the hub.
  • Automatically remove idle servers.

I really appreciate your help.

1 Like

code-server should just work, for instance this repo let’s you run it on mybinder:

You can choose which interface users are directed to by setting Spawner.default_url, e.g. c.Spawner.default_url="/lab" will go to JupyterLab.

1 Like

You may consider using jupyter-server-proxy
I compiled and wrote plugins to run several apps within jupyterlab. Not all work well, but code-server does, though you may need to adapt it to your environment:

1 Like

I was surprised but it was simple as others suggested:

# To install Server Proxy Extension for Lab
sudo /usr/local/anaconda3/bin/python3 -m pip install jupyter-server-proxy

# To Install VSCode code-server for proxying
sudo /usr/local/anaconda3/bin/python3 -m pip install jupyter-vscode-proxy

# Restart the hub for changes to apply
sudo systemctl restart jupyterhub.service

On login I see the VSCode icon next to iPython notebook :face_with_monocle:… Concerns for myself include sudo for pip and also I am not running Hub at container, so the ports are exposed for other users I think… for test & dev this worked nicely, glad to run VSCode on the same remote host as Python kernel :unicorn:

Yes, this is one of the limitations of jupyter-server-proxy. This is why it’s recommended for use only where users are isolated from each other, such as in a container.

Any one having a binder setup with versions pinned for code-server, python extension, jupyter extension where “notebooks” just works. I’ve been trying here hvplot_interactive/binder at main · MarcSkovMadsen/hvplot_interactive (github.com). But cannot get Notebook cells working. Cells are just not running.

One issue seems to be that code launches jupyter server from the preinstalled python 3.6 instead of the conda notebook environment. If I open the Interactive Window it then installs pip and ipykernel in the python 3.6 environment. Then I can change Interactive Window to conda notebook environment and work in there. Sometimes I can then even get cells in notebook to execute. But I’ve not found the exact steps yet to get it working. Seems random.

Hello
I am trying to do exactly that : using JupyterHub as a … Hub, allowing users to start either JupyterLab or Code-server images on a microk8s server.
I took the idea from nils-braun codehub too.

I am struggling on the configuration of the proxy :

  • Code-server image needs the “chp: extraCommandLineFlags: - “–no-include-prefix”” option (or i get a 404 because Code-server doesn’t handle base-url )
  • JupyterLab image needs this option to be disabled, or I get a 404

For the selection of the profile (container image), i use the “profileList” option in the value.yaml used by the Helm chart to make the deployment (see code extract below).

Do you have succeeded on this, or are you using another method ?

singleuser:
  # Defines the default image
  image:
    name: "jupyter/minimal-notebook"
    tag: "hub-2.3.0"
  storage:
    capacity: 20Mi

  profileList:
    - display_name: "minimalnotebook"
      description: "(jupyter/minimal-notebook) Jupyter"
      default: true

    - display_name: "Code-server"
      description: "(codercom/code-server:4.4.0) Code-server"
      kubespawner_override:
        image: codercom/code-server:4.4.0

@romainrossi I am running into this exact same issue - please let me know if you found a good solution!

Hi @Josh_Richardson
I didn’t found a way to really solve the issue, but I finally settled for a workaround.
The users are connected first on the JupyterLab interface, and they can click on a link to start CodeServer (see picture below).

I really think it should be possible (and even easy) to change the connection URL to redirect to the CodeServer page, but I didn’t found how.

To make my solution work, I basically installed CodeServer, server-proxy and vscode-proxy.
Here is my dockerfile (which also install a XFCE graphic server with jupyter-desktop-server) :

FROM xxxx (should work with any base image from JupyterLab project)

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# Installation des paquets pour le développement
RUN apt-get update --yes && \
    apt-get install --yes --quiet --no-install-recommends \
    curl \
    iputils-ping \
	build-essential \
    make \
    cmake \
    g++ \
    clang \
    htop \
    libopencv-dev \
    && \
    apt-get --quiet clean && rm -rf /var/lib/apt/lists/*

# Installation de Code Server et server-proxy/vscode-proxy pour intégrer Code dans JupyterLab
ENV CODE_VERSION=4.7.1
RUN curl -fOL https://github.com/coder/code-server/releases/download/v$CODE_VERSION/code-server_${CODE_VERSION}_amd64.deb \
    && dpkg -i code-server_${CODE_VERSION}_amd64.deb \
    && rm -f code-server_${CODE_VERSION}_amd64.deb
RUN /opt/conda/bin/conda install -c conda-forge jupyter-server-proxy
RUN /opt/conda/bin/conda install -c conda-forge jupyter-vscode-proxy

# Installation du bureau XFCE et de l'extention Desktop server pour avoir un affichage graphique
RUN apt-get update --yes --quiet && \
    apt-get install --yes --quiet \
    dbus-x11 xfce4 xfce4-panel xfce4-session xfce4-settings xorg xubuntu-icon-theme && \
    apt-get remove --yes --quiet light-locker && \
    apt-get clean --quiet && rm -rf /var/lib/apt/lists/*
RUN /opt/conda/bin/conda install -c manics websockify && \
    pip install git+https://github.com/yuvipanda/jupyter-desktop-server.git
 
# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}

I hope this helps, but I know this didn’t exactly solve the original issue : login directly to CodeServer.

Ahh thanks for the response!

This is essentially what I was doing before attempting to spawn code-server directly…

I will post back here if I end up figuring it out

I will test this setting, which seems promising :

https://jupyterhub-kubespawner.readthedocs.io/en/latest/spawner.html#kubespawner.KubeSpawner.default_url

Using conda to install jupyter-server-proxy, jupyter-vscode-proxy and code-server in the base environment also produces the result from your screenshot, @romainrossi.

However, to be able to run code in the VS Code editor, I had to manually install the Python extension, which also included some jupyter extensions:

After that, VS Code was able to find and connect to the right kernel.

My question is: is there a way to automate the Python extension installation, so users don’t have to do this manually every time?

It would be nice with a configuration option to include the VS Code editor with proper installations. It seems to become something that people want to do almost as much as using notebooks. Let me know if there is anything that I can do to help with this.

Hello @antonvorobets
To install an extension in the CodeServer, I would add a command in the Dockerfile.

The command to use seems to be given here :

1 Like

I have some issues with code server when it runs with JupyterHub on a GKE cluster, while it works perfectly when I test it locally in a Docker container. At first, I thought that it could be caused by an NFS server that I was running for shared data (another container), but I tried to deactivate the NFS server, and the issue still seems to persist. Based on what you are writing here, can there be an issue with having different node pools? For example, one for users and one for the hub.

It would be nice with a configuration option to include the VS Code editor as it is becoming very popular to use through a web browser. Not as a substitute for JupyterLab, but as a supplement for complex development. I will gladly help to make this happen however I can :slight_smile: