JupyterHub on k8s with Traefik

Hi everyone,

I’m having issues setting up JupyterHub on kubernetes that sits behind traefik doing path based routing to services. I’d like to have a number of different services deployed including a number of jupyterhub deployments under different namespaces and reachable via different web paths.

I’m deploying jupyterhub using the helm chart with the following configuration:

hub:
  baseUrl: /longbow-workshop/
proxy:
  secretToken: "removed"
  service:
    type: ClusterIP
rbac:
  enabled: true
singleuser:
  image:
    name: ccpbiosim/longbow-workshop
    tag: v1.0
  storage:
    type: none
  memory:
    limit: 5.0G
    guarantee: 1.0G
  cpu:
    limit: 10.0
    guarantee: 0.2
cull:
  timeout: 2400
  every: 600
prePuller:
  continuous:
    enabled: true
auth:
  type: custom
  custom:
    className: tmpauthenticator.TmpAuthenticator

with the following command:

helm upgrade --install longbow-workshop jupyterhub/jupyterhub --namespace longbow-workshop --timeout=3600 --version=0.8.2 --values longbow-workshop-helm.yaml

I then configure traefik using the basic steps here docs.traefik.io/user-guide/kubernetes/

Since my jupyterhub is in its own namespace that traefik is not deployed to I have to create a service to expose the public-proxy like this:

apiVersion: v1
kind: Service
metadata:
  name: longbow-workshop
  namespace: default
spec:
  type: ExternalName
  externalName: proxy-public.longbow-workshop.svc.cluster.local
  ports:
    - name: http
      port: 80
      targetPort: http
    - name: https
      port: 443
      targetPort: https

My Traefik ingress rules look like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ccpbiosim
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
spec:
  rules:
  - host: hubs.ccpbiosim.ac.uk
    http:
      paths:
      - path: /longbow-workshop
        backend:
          serviceName: longbow-workshop
          servicePort: http

If I then try to go to hubs.ccpbiosim.ac.uk/longbow-workshop it will redirect recursively adding /hub to the end of the url until the browser kills it and it looks like /longbow-workshop/hub/hub/hub/hub/hub/hub/hub/hub/hub/hub.

Oddly, if I configure traefik to use subdomains instead of paths then everything works fine, but it is quite time consuming for us to get A records for subdomains and would prefer to use path based routing instead. Anyone seen this before and know what I’m doing wrong?

@minrk suggested the following in the chat:

use PathPrefix instead of PathPrefixStrip . JupyterHub wants to know its absolute URL, but PathPrefixStrip is telling the hub that it’s receiving a request for / when it’s actually receiving a request for /hub/ . JupyterHub redirects requests for / to /hub/ so that’s where it’s getting caught up.

I’ll try this now and post back

2 Likes

@minrk Your solution works! And makes a lot of sense thinking about it. Thank you for your help!