mageshkrishna
k8s-kaggle-kernel-clone
TypeScriptโœจ New

Architected a distributed notebook execution environment simulating Kaggle Kernels. Utilized the Kubernetes K8s API for dynamic pod orchestration and WebSockets for real-time streaming of code execution.

Last updated Jun 5, 2026
20
Stars
2
Forks
0
Issues
0
Stars/day
Attention Score
32
Language breakdown
No language data available.
โ–ธ Files click to expand
README

Kaggle Kernel Clone

A minimal, self-hosted notebook execution platform inspired by how Kaggle Kernels work under the hood. Write Python, run cells, see output โ€” each notebook gets its own isolated Kubernetes pod.


What We're Building

Kaggle Kernels let you write and execute Python notebooks in the browser without setting up anything locally. Every time you start a session, Kaggle spins up a fresh, isolated environment just for your notebook. When you stop, it tears it down.

This project replicates that core mechanic โ€” a real notebook interface backed by live Jupyter kernels running in Kubernetes pods, with a start/stop session model exactly like Kaggle.


Inspiration

Inspired by the Kaggle infrastructure talk: How Kaggle Kernels Work โ€” YouTube

The architecture they describe:

Kaggle Kernel Architecture Inspiration


What We Built

Our implementation of the same idea โ€” notebook sessions mapped to Kubernetes pods, shared persistent storage, orchestrated through a FastAPI backend:

Our Implementation Architecture


Architecture

Browser
  โ””โ”€โ”€ HTTP / WebSocket โ”€โ”€โ–บ UI Pod (FastAPI + React)
                                โ””โ”€โ”€ spawns โ”€โ”€โ–บ Worker Pod (Jupyter Kernel)
                                                   โ””โ”€โ”€ reads/writes โ”€โ”€โ–บ Persistent Volume

Components

UI Pod

Single Kubernetes deployment running two things:
  • React frontend โ€” notebook editor with CodeMirror cells, real-time output rendering (text, HTML, images, errors), session controls in a sticky top bar
  • FastAPI backend โ€” REST API for notebook CRUD and session management, WebSocket endpoint that proxies streaming kernel output to the browser
  • Orchestrator โ€” uses the Kubernetes Python client to spawn and kill Worker Pods on demand. Tracks notebook_id โ†’ pod mapping in SQLite.

Worker Pod

One pod per notebook, created when you click Start Session, destroyed when you click Stop Session.
  • Runs an ipykernel Python process
  • Variables and imports persist across cells within a session (like a real notebook)
  • Exposes an internal HTTP API: /execute (streaming), /interrupt, /restart, /status
  • The UI Pod proxies all execution through here โ€” the browser never talks to Worker Pods directly

Persistent Volume

Shared storage mounted into every pod:
/data/
โ”œโ”€โ”€ metadata.db          โ† SQLite: notebook names, session state
โ”œโ”€โ”€ notebooks/
โ”‚   โ””โ”€โ”€ {id}.ipynb       โ† standard Jupyter notebook format
โ””โ”€โ”€ files/

Notebooks are saved as standard .ipynb files โ€” portable and compatible with Jupyter.


Tech Stack

| Layer | Technology | |---|---| | Frontend | React 18, TypeScript, Vite, CodeMirror 6 | | Backend | FastAPI, SQLAlchemy, SQLite | | Kernel | ipykernel, jupyter-client | | Orchestration | Kubernetes Python client | | Packaging | Docker (multi-stage), Helm | | Local cluster | Minikube |


Project Structure

โ”œโ”€โ”€ ui-pod/
โ”‚   โ”œโ”€โ”€ backend/              FastAPI app
โ”‚   โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”‚   โ”œโ”€โ”€ orchestrator.py   Kubernetes pod lifecycle
โ”‚   โ”‚   โ”œโ”€โ”€ routers/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ notebooks.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ sessions.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ execution.py  WebSocket + interrupt/restart
โ”‚   โ”‚   โ””โ”€โ”€ models.py
โ”‚   โ”œโ”€โ”€ frontend/             React app
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ components/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ NotebookTopBar.tsx
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ NotebookPage.tsx
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ NotebookEditor.tsx
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ Cell.tsx
โ”‚   โ”‚       โ””โ”€โ”€ api.ts
โ”‚   โ””โ”€โ”€ Dockerfile
โ”œโ”€โ”€ worker-pod/
โ”‚   โ”œโ”€โ”€ main.py               FastAPI wrapper
โ”‚   โ”œโ”€โ”€ kernel_manager.py     ipykernel interface
โ”‚   โ””โ”€โ”€ Dockerfile
โ”œโ”€โ”€ helm/kaggle-kernel/       Helm chart
โ”‚   โ”œโ”€โ”€ values.yaml
โ”‚   โ””โ”€โ”€ templates/
โ”‚       โ”œโ”€โ”€ ui-pod/
โ”‚       โ”œโ”€โ”€ storage/
โ”‚       โ””โ”€โ”€ rbac/
โ””โ”€โ”€ deploy.sh                 One-command local deploy

Running Locally with Minikube

Prerequisites

Install these before running:

1. Start Minikube

minikube start

2. Deploy

# First deploy โ€” builds Docker images and installs Helm chart
./deploy.sh --build

Subsequent deploys โ€” reinstalls chart without rebuilding images

./deploy.sh

The script handles everything:

  • Enables the ingress addon and waits for its webhook to be ready
  • Builds both images directly into Minikube's Docker daemon (no registry push needed)
  • Creates the kaggle-kernel namespace
  • Cleanly uninstalls any existing release
  • Installs the Helm chart with Minikube-compatible overrides
  • Starts a port-forward at http://localhost:8080

3. Set Up Hosts File (for Ingress)

To use the ingress at http://notebook.local instead of the port-forward:

# Get your Minikube IP
minikube ip

Example output: 192.168.49.2

Add this line to your hosts file:

Linux / macOS โ€” edit /etc/hosts:

192.168.49.2   notebook.local

Windows โ€” edit C:\Windows\System32\drivers\etc\hosts as Administrator:

192.168.49.2   notebook.local

Then open http://notebook.local in your browser.

If you skip the hosts file step, the app is available at http://localhost:8080 via the port-forward that deploy.sh starts automatically.

4. Watch the Cluster

# Watch pods come up
kubectl get pods -n kaggle-kernel -w

Tail UI Pod logs

kubectl logs -n kaggle-kernel deployment/kaggle-kernel-ui -f

How It Works โ€” Session Flow

  • Create a notebook โ†’ saved as an .ipynb file, no pod yet
  • Click Start Session โ†’ Orchestrator spawns a Worker Pod in Kubernetes, status badge shows "starting"
  • Session goes idle โ†’ Worker Pod is running, kernel is ready, badge turns green
  • Run a cell โ†’ code sent over WebSocket โ†’ executed by ipykernel โ†’ output streams back in real time
  • Click Stop Session โ†’ notebook auto-saved โ†’ Worker Pod killed โ†’ kernel state gone, outputs remain

Output

Notebook List

Output 1 โ€” Notebook list view

Notebook Editor

Output 2 โ€” Notebook editor with cell execution

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท mageshkrishna/k8s-kaggle-kernel-clone ยท Updated daily from GitHub