Install k3s + register the NVIDIA runtime.
Intermediate · on a real NVIDIA GPU
NVIDIA GPU Operator on k3s: Single-Node Kubernetes for GPU Workloads
Bring up a lightweight single-node Kubernetes cluster with the NVIDIA GPU Operator, k3s install, containerd wiring, Helm values, workload manifests with RBAC and ResourceQuota, plus a full runbook (validation plan, troubleshooting matrix, day-2 ops).
$29.99 a month with Pro. It opens this lab and every other one. Cancel any time.
The 4 steps
each one checked
A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.
- 1
Install k3s + register the NVIDIA runtime
Read this step
Install k3s in server mode. We write out the exact command you'd run on the node, plus the containerd config snippet that tells k3s how to launch pods under the NVIDIA runtime.
Why the config path matters: k3s uses a distinct containerd under
/var/lib/rancher/k3s/agent/etc/containerd/. The default NVIDIA installer patches/etc/containerd/config.tomlwhich k3s ignores. You must either configure k3s to use the system containerd, or drop a template file into k3s's path. We do the latter — cleaner, fully managed by k3s.from pathlib import Path from IPython.display import Code, display WORKSPACE = Path('/home/labuser/workspace') # Load the k3s install script + containerd config template from the workspace. # Authoring them as real files (instead of Python triple-quoted strings) lets you # `shellcheck scripts/install_k3s.sh`, diff them in git, and re-use them outside # the notebook. k3s_install_script = (WORKSPACE / 'scripts/install_k3s.sh').read_text() nvidia_runtime_config = (WORKSPACE / 'containerd/config.toml.tmpl').read_text() display(Code(filename=str(WORKSPACE / 'scripts/install_k3s.sh'), language='bash')) display(Code(filename=str(WORKSPACE / 'containerd/config.toml.tmpl'), language='toml')) # Post-install sanity checks — each one catches a real failure mode post_install_checks = [ { 'step': 'node ready', 'command': 'kubectl get nodes -o wide', 'expected_output': 'STATUS column shows Ready; Container-Runtime shows containerd://... on the node', }, { 'step': 'containerd knows nvidia', 'command': 'sudo grep -A3 "runtimes.nvidia" /var/lib/rancher/k3s/agent/etc/containerd/config.toml', 'expected_output': 'block present with BinaryName = "/usr/bin/nvidia-container-runtime"', }, { 'step': 'host driver visible', 'command': 'nvidia-smi', 'expected_output': 'lists the GPU, driver version, CUDA version, no processes at idle', }, { 'step': 'test pod sees GPU', 'command': 'kubectl run gpu-smoke --rm -it --image=nvidia/cuda:12.4.1-base-ubuntu22.04 ' '--overrides=\'{"spec":{"runtimeClassName":"nvidia","containers":[{"name":"gpu-smoke","image":"nvidia/cuda:12.4.1-base-ubuntu22.04","command":["nvidia-smi"],"resources":{"limits":{"nvidia.com/gpu":1}}}]}}\' -- nvidia-smi', 'expected_output': 'pod runs to completion and prints nvidia-smi output listing the GPU', }, { 'step': 'kubeconfig permissions', 'command': 'ls -la /etc/rancher/k3s/k3s.yaml', 'expected_output': 'mode 644 (or 600 if you ran without --write-kubeconfig-mode) — NOT world-writable', }, ] print(f"\n{len(post_install_checks)} post-install checks:") for chk in post_install_checks: print(f" [{chk['step']}] {chk['command'][:80]}...") print(f" expect: {chk['expected_output'][:80]}") - 2
Install the NVIDIA GPU Operator via Helm
- 3
Workload manifests: Namespace, RuntimeClass, Pod, RBAC, ResourceQuota
- 4
The runbook: validation, troubleshooting, day-2 ops
Before you start
3 things
- Kubernetes basics, Pods, Deployments, Namespaces, RBAC
- Helm charts and values.yaml overrides
- Linux CLI, systemd, containerd fundamentals
What you get
- A JupyterLab notebook on a real NVIDIA GPU
- A check at the end of every step
- Hints and the full solution
- Nothing to install or configure
Exam domains covered
NCP-AIO, NCP-AIN, NCP-AII, NCA-AMAD
The GPU and Kubernetes track
lab 2 of 20
GPU scheduling on your own Kubernetes cluster, the GPU Operator, CUDA kernels and profiling.
- Beginner · 5 min · Kubernetes · ProWelcome to NCA-AIIO Labs: Schedule Your First GPU Pod
- this labNVIDIA GPU Operator on k3s: Single-Node Kubernetes for GPU Workloads
- Intermediate · 35 min · Kubernetes · ProInside the NVIDIA GPU Operator: From Helm to Workload-Ready
- Intermediate · 40 min · Kubernetes · ProKubernetes Resource Requests & Limits: Who Gets What, and Who Survives
- Intermediate · 35 min · Kubernetes · ProMulti-GPU-Type Targeting: nodeSelector, nodeAffinity & Tolerations
- Intermediate · 35 min · Kubernetes · ProPriorityClass & Preemption: Who Survives the GPU Squeeze
- Intermediate · 35 min · Kubernetes · ProWorkload Controllers: Deployment, StatefulSet, DaemonSet for AI
- Intermediate · 35 min · Kubernetes · ProPersistent Storage for AI Workloads: PVCs, StorageClass & the Checkpoint Pattern
- Intermediate · 40 min · NVIDIA GPU · ProGPU Container Lifecycle: Build, Test, Ship, Rollback
- Intermediate · 35 min · Kubernetes · ProRolling Updates, Rollback & Blue-Green for AI Inference
- Intermediate · 40 min · Kubernetes · ProStuck-Pending Triage Day: Diagnose Any GPU Pod That Won't Run
- Intermediate · 40 min · NVIDIA GPU · ProGPU Observability: From nvidia-smi to a Production Monitoring Stack
- Advanced · 50 min · NVIDIA GPU · ProGPU Health Checks + Auto-Remediation
- Advanced · 45 min · NVIDIA GPU · ProCUDA Programming Fundamentals
- Intermediate · 35 min · NVIDIA GPU · ProProfile PyTorch Training with the Built-in Profiler
- Intermediate · 35 min · NVIDIA GPU · ProNsight Systems Profiling: Finding the Bottleneck That Costs You 40% of Your GPU
- Advanced · 45 min · NVIDIA GPU · ProGPU Sharing: Streams, MPS, MIG, and the Real Cost of Contention
- Intermediate · 30 min · NVIDIA GPU · ProNVIDIA DALI: GPU-Accelerated Data Pipelines
- Intermediate · 40 min · NVIDIA GPU · ProGPU-Accelerated Data Science with RAPIDS
- Intermediate · 35 min · NVIDIA GPU · ProGPU Cost & Efficiency Audit
Questions about this lab
6 answers
Why k3s instead of full upstream Kubernetes for a GPU lab?
Because k3s is the shortest path to a working single-node cluster on a dev box, one binary, one curl-to-install, sensible defaults, and everything runs under one systemd unit. Upstream Kubernetes needs kubeadm, a separate CRI, separate CNI setup, and a lot more to go right on the first try. For production multi-node GPU clusters you'd reach for RKE2, OpenShift, or managed EKS/AKS/GKE, but for learning the operator-and-runtime chain, k3s is the right default.
Why set driver.enabled: false in the GPU Operator values?
driver.enabled: false in the GPU Operator values?Because the lab assumes the NVIDIA driver is already installed on the host (which is how most dev boxes and cloud GPU VMs ship). The GPU Operator can install and manage the driver itself in a container, but doing that requires unloading the running driver first and is the wrong default on a machine you use for other things. driver.enabled: false tells the operator to trust the host driver and only manage the pieces above it: toolkit, device plugin, NFD, dcgm-exporter.
Why does the toolkit.env path need to point at /var/lib/rancher/k3s/agent/etc/containerd?
toolkit.env path need to point at /var/lib/rancher/k3s/agent/etc/containerd?Because k3s ships its own containerd and puts its config at a non-standard path under /var/lib/rancher/k3s/agent/etc/containerd/config.toml, generated from config.toml.tmpl. The NVIDIA container toolkit's job is to patch the containerd config so the nvidia runtime is registered, if it patches the standard /etc/containerd/config.toml (which is what the default operator values target), k3s never reads those changes and the GPU resource is never advertised to the device plugin.
What does the RuntimeClass named nvidia actually do?
nvidia actually do?It lets Kubernetes select a specific container runtime on a per-pod basis. When a pod sets runtimeClassName: nvidia, kubelet tells containerd to start the container using the nvidia runtime entry (the one you configured in Step 1), which wraps runc with the NVIDIA container toolkit and injects the GPU device nodes into the container. Without the RuntimeClass, pods get the default runtime and the GPU isn't visible, even if nvidia.com/gpu: 1 is requested correctly.
Why is 0/1 nodes available: insufficient nvidia.com/gpu almost never a workload bug?
0/1 nodes available: insufficient nvidia.com/gpu almost never a workload bug?Because that message means the device plugin never advertised the resource to the Kubernetes scheduler at all. The fix is in the lower layers: the toolkit DaemonSet didn't patch containerd, or the patch landed at the wrong path, or the driver isn't loaded, or NFD didn't label the node. The reflection step walks you bottom-up through the runbook: host nvidia-smi → containerd config on disk → operator pods healthy → NFD labels on the node → device plugin advertising the resource. The workload's runtimeClassName is the last thing to check, not the first.
Why cap GPUs with a ResourceQuota if the node only has a fixed number anyway?
Because namespace-level ResourceQuotas prevent one tenant (a team, a project, a CI pipeline) from monopolizing the cluster's GPUs. Without a quota, a misbehaving workload that requests nvidia.com/gpu: 4 can leave every other namespace waiting. With spec.hard.requests.nvidia.com/gpu: 2 you pin each namespace's budget, and the scheduler will reject over-quota requests at admission time rather than letting them pile up Pending. It's cheap insurance against noisy neighbors even on a single-node dev cluster.
What you'll build in this k3s + NVIDIA GPU Operator lab
about
Running GPUs on Kubernetes is where AI platform teams earn their keep, the NVIDIA GPU Operator is the glue, and understanding its chain (host driver → containerd → NVIDIA container toolkit → device plugin → NFD → dcgm-exporter → your pod) separates operators who can debug 0/1 nodes available: insufficient nvidia.com/gpu in five minutes from teams that lose an afternoon to it. This lab gives you a complete, production-shaped artifact set for a single-node k3s cluster: a k3s install script with the right INSTALL_K3S_EXEC flags, a containerd runtime snippet registering nvidia-container-runtime, a gpu-operator Helm values.yaml tuned for k3s, workload manifests with RuntimeClass and ResourceQuota, and a runbook with validation, troubleshooting, and day-2 ops. Roughly 40 minutes on a real NVIDIA GPU pod we provision, no local cluster, no driver install, no CNI wrangling.
The k3s + GPU Operator pairing is a specific production choice and the lab treats it that way. You'll set driver.enabled: false because the host already has the driver (the right default on dev boxes and cloud GPU VMs), point toolkit.env at /var/lib/rancher/k3s/agent/etc/containerd, not /etc/containerd/, because k3s ships its own containerd at a non-standard path, enable NFD + device plugin + dcgm-exporter, and define a RuntimeClass named nvidia so pods explicitly opt into the GPU runtime. The ResourceQuota on requests.nvidia.com/gpu is the multi-tenant guardrail that stops one namespace monopolising the card. The runbook walks the layered chain bottom-up, host nvidia-smi → containerd config on disk → operator pods healthy → NFD labels → device plugin advertising nvidia.com/gpu → workload runtimeClassName, because every mysterious Pending pod on a GPU cluster is a failure somewhere in that chain, and the fastest path to root cause is always bottom-up.
Prereqs: Kubernetes fundamentals (Pods, Deployments, Namespaces, RBAC), Helm values overrides, and Linux basics (systemd, containerd, TOML config). Preinstalled on the lab pod: k3s, Helm 3, kubectl, the NVIDIA driver, containerd, PyYAML for the grader. The notebook is a writing exercise, grading parses your YAML and asserts structural correctness (multi-doc manifests, required fields, canonical MIG/containerd paths, runbook field schema), so you practice the artifacts exactly as you'd ship them to a real cluster.