1 × RTX 5060 · 8 GB · Blackwell sm_120 · CUDA 13.4 · Ryzen 5 8400F4 posts · 0 errata · last measurement 2026-11-16
Kokou
← Posts

k3s GPU Cluster

k3s won the comparison but dies a minute after the last terminal closes, and its GPU rationing is opt-in. This is how I turned it into a cluster I can leave running, and drive with one command.

2026-11-145 mincost: $0 · one machineNeuroMeshchangelog
gpu
1 × RTX 5060, 8 GB, the one on my desk
available
desktop share not measured for this run
cost
$0 · one machine

In the comparison, k3sk3s A small Kubernetes distribution that ships as one binary. Mine runs inside a WSL2 distro as the gpu-lab cluster. Glossary was the fastest and lightest way to run GPU pods on this machine, and the only one besides minikube where those pods run unprivileged. It also came with two catches: WSL stops its distro about a minute after the last terminal closes, taking the cluster with it, and any pod that names the nvidia RuntimeClassRuntimeClass A Kubernetes object that picks which runtime handler starts a pod's containers. The nvidia class adds the GPU libraries; without it a GPU pod can schedule, report Running and still find no CUDA device. Glossary gets the GPU whether or not it asked for it.

Both had to go before the cluster could carry anything I care about. The result is gpu-lab, run by task cluster:* from NeuroMesh’s tools/cluster, and shared by NeuroMesh and this blog.

1. Goals

The cluster had to:

  • stay up with no terminal open, and come back on its own after wsl --shutdown or a reboot;
  • advertise the GPU so the scheduler rations it, with no way for a pod to go around that;
  • be built, paused, resumed and removed by one command each, where running a command twice changes nothing;
  • serve both NeuroMesh and the harnesses on this blog.

Out of scope: more than one node, a local image registry, and the Windows relay. Those are still open on NeuroMesh#21.

2. Keepalive

wsl.exe exits 0 when its distro is terminated, so restart-on-failure never fires.

WSL stops a distro about a minute after its last wsl.exe session ends. A k3s server in that distro stops with it, and every pod gets recreated when something wakes it again. So something has to hold a session open.

My first keepalive was a per-user Scheduled Task, started at logon, running a hidden wsl.exe -d Ubuntu --exec /bin/sleep infinity with restart-on-failure every minute. No admin and no window. It held the cluster up fine, until I tested wsl --terminate: wsl.exe exited cleanly, Task Scheduler recorded success, and nothing restarted. The cluster stayed down.

The task has to loop by itself:

while ($true) { & wsl.exe -d Ubuntu --exec /bin/sleep infinity; Start-Sleep -Seconds 5 }
What stopped itKeepaliveNode ReadyGPU allocatable
wsl --shutdownlooping task1436
wsl --terminatetask that runs wsl.exe oncestayed downstayed down
wsl --terminatelooping task1220
15 minutes with no terminal openlooping taskstayed Readystayed 1

How long the cluster takes to come back, in seconds, from the timestamps in the raw output.

With the loop, the node is Ready 14 seconds after wsl --shutdown and the GPU is allocatable again at 36 seconds; the difference is the device plugindevice plugin A pod on each node that tells the kubelet how many of a device it has. NVIDIA's advertises GPUs as nvidia.com/gpu, so the scheduler can hand them out like CPU or memory. Glossary re-registering. Left alone for 15 minutes with no terminal of mine open, the node stayed Ready with nothing restarted.

3. Device plugin

The NVIDIA device plugin, as published, sat at Running on k3s with no restarts and never registered a GPU. Its log said why:

Incompatible strategy detected auto
invalid device discovery strategy

The plugin counts the card through NVMLNVML NVIDIA's C library for reading a GPU's memory, utilisation, power and clocks. nvidia-smi and most monitoring tools are built on it, and my harnesses call it from Python through nvidia-ml-py. Glossary, so its own pod needs the driver, and on k3s the driver only reaches pods that use the nvidia RuntimeClass. One line on its DaemonSetDaemonSet Runs one copy of a pod on every node, or every node that matches. Device plugins and log collectors are usually DaemonSets. Glossary fixes it:

spec:
  template:
    spec:
      runtimeClassName: nvidia

After that the log reads Detected platform: wsl and Registered device plugin for 'nvidia.com/gpu', and the node shows nvidia.com/gpu: 1. Time-slicingtime-slicing A device plugin setting that advertises one GPU as several nvidia.com/gpu, so pods share it by taking turns. There's no memory isolation, so one pod can still take all of it. Glossary stays at one replica: the cluster is shared with the VRAM measurements on this blog, and time-slicing shares compute, not memory, so every replica would see the whole card.

4. Admission policy

With the RuntimeClass and the device plugin both in place, there are still two ways to get it wrong:

  • a pod that names the RuntimeClass without requesting nvidia.com/gpu gets the GPU, and the scheduler thinks the card is free;
  • a pod that requests nvidia.com/gpu without the RuntimeClass holds the card with no driver in it.

A ValidatingAdmissionPolicyadmission policy A rule the API server checks before it accepts an object, written in CEL. Mine rejects a GPU pod that has the GPU request without the RuntimeClass, or the other way round. Glossary rejects both, so the only pod that reaches the GPU is one the scheduler counted:

validations:
- expression: "!variables.nvidiaRuntime || variables.wantsGpu"
  message: runtimeClassName nvidia without a nvidia.com/gpu limit would use the GPU without the scheduler knowing.
- expression: "!variables.wantsGpu || variables.nvidiaRuntime"
  message: nvidia.com/gpu requested without runtimeClassName nvidia would hold the GPU with no driver.

kube-system is exempt, because the device plugin itself runs with the RuntimeClass and requests nothing. With the policy in place, “is nvidia.com/gpu allocated” is a complete answer to “is anyone else on the card”, which is exactly what the VRAM harness (#10) checks before it measures.

5. One cluster

I wanted NeuroMesh to have its own distro and its own cluster. It can’t: every plain WSL2 distro on this machine shares one network namespace, so a second k3s finds ports 6443 and 10250 already taken by the first. So there is one cluster, gpu-lab, and both repositories use it. The rule that follows is that before any VRAM measurement, no pod holds the GPU and NeuroMesh’s GPU workloads are scaled to zero.

Two smaller fixes came out of sharing it:

  • The kubeconfig stays readable. k3s rewrites /etc/rancher/k3s/k3s.yaml as root-only on every start, so kubectl inside WSL broke after every restart until I set write-kubeconfig-mode: "0644".
  • Windows kubectl doesn’t depend on the node’s IP. The gpu-lab context points at localhost:6443, which WSL forwards, so it survives the distro getting a new address.

6. Commands

Everything above is set up and checked by six commands:

task cluster:start     # set up or fix the cluster, wait for Ready and the GPU
task cluster:status    # check every layer from the Windows driver up; -- -probe also runs a GPU pod
task cluster:pause     # stop k3s and every pod; keep the node, volumes and images
task cluster:resume
task cluster:stop      # pause, then let the distro stop and give its memory back
task cluster:delete -- -yes
CommandRunSecondsWhat changed
startfirst run after a config change7.7config.yaml, device plugin manifests, k3s restarted
startsecond run2.2nothing
pause4.0k3s stopped and disabled; node, volumes and images kept
resumeafter pause20.5k3s started; Ready and nvidia.com/gpu allocatable
stop5.2k3s stopped, keepalive task disabled, Ubuntu terminated
resumeafter stop23.7keepalive enabled and started, k3s started; Ready and nvidia.com/gpu allocatable

Wall time for each command on this machine, and what it changed.

start prints ok or changed for every piece it manages, so a second run is a list of ok lines and takes about two seconds. pause and stop keep the node, its volumes and its images; I checked by writing a marker file to a volume before pausing and reading it back after resuming. delete without -yes only lists what it would remove (k3s with every pod, volume and image, /etc/rancher and /var/lib/rancher, the keepalive task, and the gpu-lab entries in the Windows kubeconfig) and that it keeps the distro and the toolkit.

7. Status

task cluster:status checks each layer in the order a GPU reaches a pod, and stops being green at the first one that is broken:

✅ Windows driver      NVIDIA GeForce RTX 5060, 621.01
✅ keepalive           task "gpu-lab keepalive" running
✅ WSL distro          Ubuntu running
✅ WSL passthrough     /dev/dxg present
✅ container toolkit   nvidia-container-toolkit 1.20.1-1
✅ k3s                 v1.36.5+k3s1
✅ k3s service         active, enabled at boot
✅ containerd runtime  nvidia runtime configured
✅ node                gpu-lab Ready
✅ RuntimeClass        nvidia -> nvidia
✅ device plugin       1 pod ready
✅ nvidia.com/gpu      1 allocatable
✅ admission policy    GPU request and RuntimeClass must come together
✅ GPU in use          no running pod holds nvidia.com/gpu
✅ kubeconfig          context gpu-lab in the Windows kubeconfig

With -probe it also runs a plain ubuntu:24.04 pod, with no driver and no binaries of its own, that has to list the card with nvidia-smi -L, and checks that the policy rejects both half-shaped pods. Run in the seconds after wsl --shutdown, before the device plugin is back, it says exactly what is still coming up:

❌ device plugin       "0/1" ready: check `kubectl -n kube-system logs ds/nvidia-device-plugin-daemonset`
❌ nvidia.com/gpu      not allocatable: a plugin that is Running but logs `Incompatible strategy` lacks runtimeClassName

The same walk, without a cluster to run it against, is the lab’s layer triage.

8. What’s left

NeuroMesh#21 stays open for the parts this doesn’t cover yet: a local registry mirror and the task image:* path (NeuroMesh#14), the Windows relay, sizing .wslconfig from the machine instead of by hand, and the decision about CI.

The numbers here are in data/k3s-wsl2-gpu/, and the code is in NeuroMesh at the commit in the environment block.

If your numbers disagree with mine, I want to hear it.

9. Sources

Changelog

  • 2026-11-14Published.