Self-hosting

This guide deploys LabCluster to a Kubernetes cluster with continuous delivery from GitHub. It is the setup the public instance uses, and it works on any conformant cluster whose network plugin enforces NetworkPolicy.

What you need

Component Recommendation Why
Kubernetes cluster Any managed, conformant cluster with a NetworkPolicy-enforcing CNI (for example Cilium or Calico), x86-64 nodes (the release workflow builds amd64 images), in the region closest to your learners Session isolation relies on network policies; the control-plane binaries are x86-64 builds
Postgres A managed Postgres 16 or newer in the same region The only state that outlives a session; managed backups
Domain and edge A domain on Cloudflare, with a Cloudflare Tunnel TLS, caching and WebSockets at the edge, no public IP or load balancer on the cluster
Images GitHub Container Registry Built and pushed by the release workflow
Sign-in A GitHub OAuth app The only sign-in method

Sizing

Each running session uses two pods in its own namespace:

Pod Requests Limits
Control plane (API server, etcd, scheduler, controller-manager, kwok) 250m CPU, 384 MiB 1 CPU, 1 GiB
Terminal 50m CPU, 64 MiB 500m CPU, 256 MiB

So every concurrent session reserves about 0.3 CPU and 450 MiB. The platform itself (two website replicas, the controller and two cloudflared replicas) reserves well under 1 CPU and 1 GiB. Size the node pool for your session cap (LABCLUSTER_GLOBAL_CAP) with headroom for the limits, and raise the cap as you observe real usage.

One-time setup

1. Repository and images

Push the repository to GitHub. The release workflow builds and pushes two images on every push to main:

  • ghcr.io/<owner>/labcluster: the website, controller, session host, labs and control-plane binaries;
  • ghcr.io/<owner>/labcluster-terminal: the learner terminal.

After the first run, make both packages public in the repository’s package settings, or give the cluster a pull secret.

2. Postgres

Create a database and a user, and note the connection string, for example postgres://labcluster:<password>@<host>:5432/labcluster?sslmode=require. The website creates and migrates its tables on start.

3. GitHub OAuth app

In GitHub, go to Settings → Developer settings → OAuth Apps → New OAuth App:

  • Homepage URL: https://<your-domain>
  • Authorization callback URL: https://<your-domain>/auth/github/callback

Generate a client secret and note the client ID.

4. Cloudflare Tunnel

In the Cloudflare dashboard, create a tunnel, copy its token, and add a public hostname for your domain with the service http://labcluster-web.labcluster-system.svc.cluster.local:80. Cloudflare Tunnel supports WebSockets, which the browser terminal needs.

5. Configure the overlay

Edit deploy/overlays/production/config.env:

LABCLUSTER_PUBLIC_URL=https://<your-domain>
LABCLUSTER_REPO_URL=https://github.com/<owner>/labcluster
LABCLUSTER_GLOBAL_CAP=10     # concurrent sessions across the platform
LABCLUSTER_PER_DAY=3         # sessions per learner per 24 hours

and replace OWNER in deploy/overlays/production/kustomization.yaml and release.env with your GitHub owner (the deploy workflow overwrites the image tags on every release).

6. Secrets

kubectl create namespace labcluster-system
kubectl label namespace labcluster-system pod-security.kubernetes.io/enforce=restricted
kubectl -n labcluster-system create secret generic labcluster-web \
  --from-literal=DATABASE_URL='postgres://...' \
  --from-literal=GITHUB_CLIENT_ID='...' \
  --from-literal=GITHUB_CLIENT_SECRET='...'
kubectl -n labcluster-system create secret generic cloudflared --from-literal=token='<tunnel token>'

7. First deploy

kubectl apply -k deploy/overlays/production
kubectl -n labcluster-system rollout status deploy/labcluster-web deploy/labcluster-controller

Open your domain, sign in with GitHub and start a lab.

8. Continuous delivery

The deploy workflow runs after each successful release on main. It pins the overlay to the images built from that commit, applies it, and waits for the rollout. It needs:

  • a GitHub environment named production (add required reviewers there if you want a manual approval step);
  • an environment secret KUBECONFIG containing a kubeconfig for a service account that may apply the overlay.

Reference setup: GKE Spot, Neon and Cloudflare

The public instance at labcluster.dev runs on the lowest-cost combination that meets the requirements above:

Piece Choice Cost
Cluster GKE Standard, one zonal cluster in us-east5-a (Columbus, Ohio), GKE Dataplane V2 (NetworkPolicy always on) Cluster fee covered by GKE’s free tier (one zonal or Autopilot cluster per billing account)
Nodes One autoscaled node pool of Spot VMs, e2-standard-4, 1 to 3 nodes Spot price, up to 91% below on-demand
Postgres Neon, region aws-us-east-2 (Ohio, the same area as us-east5) Free plan; scales to zero when idle
Edge Cloudflare Tunnel on the free plan Free

Spot VMs can be reclaimed at any time. A reclaimed node ends the sessions on it (learners start a new one) and the website reschedules within a minute or two; the cluster autoscaler replaces the node. For guaranteed uptime add a small on-demand node pool for labcluster-system.

gcloud container clusters create labcluster \
  --zone us-east5-a --release-channel regular --enable-dataplane-v2 \
  --spot --machine-type e2-standard-4 --disk-size 50 \
  --num-nodes 1 --enable-autoscaling --min-nodes 1 --max-nodes 3
gcloud container clusters get-credentials labcluster --zone us-east5-a

In Neon, create a project in AWS US East (Ohio), create a database labcluster on the production branch, and copy its direct (not pooled) connection string with sslmode=require as DATABASE_URL. The website closes idle database connections after a minute and its readiness probe does not query the database, so Neon’s compute can suspend when nobody is using the site.

Configuration reference

Variable Used by Default Description
LABCLUSTER_PUBLIC_URL web required Public base URL: OAuth callback, canonical links, sitemap
LABCLUSTER_REPO_URL web upstream repository Links to the source, issues and “edit this page”
DATABASE_URL web required Postgres connection string
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET web required GitHub OAuth app
LABCLUSTER_GLOBAL_CAP web 40 Concurrent sessions across the platform
LABCLUSTER_PER_DAY web 3 Sessions per learner per 24 hours
LABCLUSTER_IMAGE controller required Platform image for session control-plane pods
LABCLUSTER_TERMINAL_IMAGE controller required Terminal image
LABCLUSTER_SESSIONS controller pod pod for production; local only for development
LABCLUSTER_SESSION_RETENTION controller 1h How long ended LabSession objects are kept on the host

Operating it

  • Health: the website serves /healthz (process up) and /readyz (database reachable).
  • Sessions: kubectl get labsessions lists them with their phase, lab and age; each has a namespace lab-<id>.
  • Cost control: lower LABCLUSTER_GLOBAL_CAP to cap spend; learners see a “try again in a few minutes” message when it is reached.
  • Upgrades: merge to main. The controller runs as a single replica with the Recreate strategy, so sessions being provisioned during a controller restart are marked Interrupted and do not count against the learner’s day; running sessions continue.
  • Backups: rely on your Postgres provider’s backups. Nothing else needs backing up.

Edit this page on GitHub