Enable NVIDIA GPUs on a Bare-Metal Kubernetes Node
Goal
Let pods on a Debian node use its NVIDIA GPU, for transcoding or ML, in three layers: the kernel driver on the host, the NVIDIA runtime in containerd, and the device plugin that tells Kubernetes the GPU exists.
Prerequisites
- A Debian node with an NVIDIA GPU, already in the cluster.
- Secure Boot disabled in the firmware, or a Machine Owner Key enrolled to sign the module (see DKMS Builds a Driver Against the Running Kernel, So Missing Headers or Secure Boot Leave It Unloaded). Check before installing:
sudo apt-get install -y mokutil && mokutil --sb-state. - The
contrib,non-freeandnon-free-firmwarecomponents enabled in the node's apt sources.
Steps
1. Install the Driver on the Host
- Install the kernel headers with the driver, so that DKMS can build the module:
sudo apt-get update sudo apt-get install -y linux-headers-amd64 nvidia-driver firmware-misc-nonfree - Check that the module was built for the running kernel:
If it sayssudo dkms status # want "...: installed"; "added" means the build failedadded, install the headers and rebuild:sudo dpkg-reconfigure nvidia-kernel-dkms. - Reboot, then run
nvidia-smi: it must list the GPU.
2. Plug the NVIDIA Runtime into containerd
-
Add NVIDIA's repository and install the Container Toolkit:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \ | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \ | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \ | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit -
Register the runtime in containerd's configuration, as the default unless your pods select a RuntimeClass:
sudo nvidia-ctk runtime configure --runtime=containerd --set-as-default -
Restart containerd: it reads its configuration only at startup.
sudo systemctl restart containerdRecent toolkit versions don't edit
config.tomlitself: they write/etc/containerd/conf.d/99-nvidia.tomland add animportsline. Check the merged result, not the main file:sudo containerd config dump | grep -E 'default_runtime_name|SystemdCgroup'Expect
default_runtime_name = "nvidia"andSystemdCgroup = trueon both runtimes (see containerd Merges Drop-in Files Through imports, So config dump Shows the Real Config).Cap the open-files limit containers inherit (containerd 1.7 sets
LimitNOFILE=infinity, andnvidia-smiin a container then tries to allocate tens of gigabytes; see containerd 1.7 Gives Containers a Billion-File Limit, So Code Sized by It Can Exhaust a Node's RAM):sudo mkdir -p /etc/systemd/system/containerd.service.d printf '[Service]\nLimitNOFILE=1024:524288\n' | sudo tee /etc/systemd/system/containerd.service.d/10-limitnofile.conf sudo systemctl daemon-reload && sudo systemctl restart containerd systemctl show containerd -p LimitNOFILESoft -p LimitNOFILE # 1024 and 524288
3. Advertise the GPU to Kubernetes
-
Deploy the device plugin from its Helm chart (
nvidia-device-pluginfromhttps://nvidia.github.io/k8s-device-plugin, pinned, e.g. 0.20.0), from the admin workstation or as a GitOps Application. Never from the GPU node: workers have no kubeconfig. Two values matter:- Affinity. The chart's default affinity only matches nodes labelled by Node Feature Discovery or GPU Feature Discovery (
feature.node.kubernetes.io/pci-10de.present=trueornvidia.com/gpu.present=true). Without those, the DaemonSet installs fine and runs nowhere. Either enable GFD/NFD, or give the plugin an affinity on your own GPU label:
The chart already tolerates theaffinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - {key: homelab/gpu, operator: In, values: ["nvidia"]}nvidia.com/gpu:NoScheduletaint. - Sharing (optional). To let several pods share the card, add a time-slicing config under
config.mapand name it inconfig.default(see Time-Slicing Lets Pods Share a GPU but Not Isolate Its Memory).
If the plugin was already running before step 6, restart its DaemonSet so it sees the new runtime:
kubectl -n <namespace> rollout restart ds -l app.kubernetes.io/name=nvidia-device-plugin. - Affinity. The chart's default affinity only matches nodes labelled by Node Feature Discovery or GPU Feature Discovery (
-
Request the GPU in the pod's resources, like CPU or memory:
resources: limits: nvidia.com/gpu: 1
Verify
-
kubectl describe node <gpu-node> | grep nvidia.com/gpushows1under Capacity and Allocatable (or the number of time-slicing replicas). - The pod requesting the GPU is
Running, andkubectl exec <pod> -- nvidia-smiprints the full table. - A new container shows the capped limits:
kubectl exec <pod> -- sh -c 'ulimit -Sn; ulimit -Hn'gives1024and524288.
Troubleshooting
nvidia-smifails after the reboot: checkdkms status(headers) and Secure Boot (mokutil --sb-state).- Pods
PendingwithInsufficient nvidia.com/gpu: the plugin isn't advertising the GPU. Usually containerd wasn't restarted after step 5, or the plugin started before it was. - Device plugin logs
Incompatible strategy detected auto: the plugin is running with the defaultruncruntime, which can't see the GPU. Make the NVIDIA runtime the default (step 5), or give the plugin a RuntimeClass that uses it. config.tomlstill saysdefault_runtime_name = "runc"after step 5: look atcontainerd config dumpbefore changing anything; the NVIDIA default may be set in a drop-in file.- Running the device-plugin restart on the GPU node fails with
localhost:8080 refused: a worker has no kubeconfig. Runkubectlfrom the admin workstation, or deploy the plugin through GitOps. - The GPU is already taken: each
nvidia.com/gpugoes to one container at a time. A second pod requesting it staysPendinguntil the first one releases it, unless the plugin time-slices the card. - The plugin DaemonSet shows
DESIRED 0: its affinity matches no node. Check the node's labels against the chart's affinity (step 7). - The full
nvidia-smiin a container freezes the node, butnvidia-smi -Lworks: it's memory, not the GPU. Checkulimit -Hnin the container: about a billion means containerd still hasLimitNOFILE=infinity(end of step 6). The kernel log showsOut of memory: Killed process … (nvidia-smi)when the OOM killer wins the race. nvidia-smi --query-gpu=persistence_modesaysDisabledalthoughnvidia-persistencedruns: query it as root; an unprivileged user getsDisabled.- A video app (Jellyfin) uses NVENC but the GPU decoder stays at 0 % and the CPU is busy: decoding isn't on the GPU. Check that the source codec is in the app's hardware-decoding list; on my server Jellyfin had saved only H264 and VC1, so HEVC was decoded on the CPU (~690 % → ~85 % CPU once fixed, 2026-11). And
nvidia-smiat 0 % during playback can be right: a client that plays the codec itself gets the video copied, not transcoded. h264_nvencfails with-22 (Invalid argument)on a 10-bit file: NVENC's H.264 encoder only accepts 8-bit frames. Convert on the GPU first (-vf scale_cuda=format=nv12, or a tone-mapping filter for HDR); a 4K HEVC 10-bit → 720p H.264 test then ran at 11.6× real time on a GTX 1070.
References
- DKMS Builds a Driver Against the Running Kernel, So Missing Headers or Secure Boot Leave It Unloaded - why the driver install can fail silently.
- Kubernetes Schedules a GPU Only After a Device Plugin Advertises It as an Extended Resource - how the three layers fit together.
- kubelet Depends on containerd Through the CRI Socket - why containerd changes need a restart.
- containerd Merges Drop-in Files Through imports, So config dump Shows the Real Config - verifying the runtime the toolkit configured.
- containerd 1.7 Gives Containers a Billion-File Limit, So Code Sized by It Can Exhaust a Node's RAM - why the open-files limit matters for GPU containers.
- Kubernetes MOC - hub for Kubernetes notes.
- NVIDIA Developer Forums: "Nvidia-smi uses all of ram and swap" - NVIDIA's acknowledgement of the
nvidia-persistencedbug and the lower-limit workaround (last checked 2026-11). - Debian Wiki: NvidiaGraphicsDrivers - the driver packages and the repository components they need.
- NVIDIA Container Toolkit: Installation Guide - repository setup and
nvidia-ctk runtime configure. - NVIDIA k8s-device-plugin - the chart, its values (affinity,
config.map) and requirements (v0.20.0, last checked 2026-11). - Kubernetes documentation: Schedule GPUs - requesting GPUs in pods.