Enable NVIDIA GPUs on a Bare-Metal Kubernetes Node

In progress Kubernetes Linux

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

Steps

1. Install the Driver on the Host

  1. 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
    
  2. Check that the module was built for the running kernel:
    sudo dkms status   # want "...: installed"; "added" means the build failed
    
    If it says added, install the headers and rebuild: sudo dpkg-reconfigure nvidia-kernel-dkms.
  3. Reboot, then run nvidia-smi: it must list the GPU.

2. Plug the NVIDIA Runtime into containerd

  1. 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
    
  2. 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
    
  3. Restart containerd: it reads its configuration only at startup.

    sudo systemctl restart containerd
    

    Recent toolkit versions don't edit config.toml itself: they write /etc/containerd/conf.d/99-nvidia.toml and add an imports line. Check the merged result, not the main file:

    sudo containerd config dump | grep -E 'default_runtime_name|SystemdCgroup'
    

    Expect default_runtime_name = "nvidia" and SystemdCgroup = true on 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, and nvidia-smi in 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

  1. Deploy the device plugin from its Helm chart (nvidia-device-plugin from https://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=true or nvidia.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:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - {key: homelab/gpu, operator: In, values: ["nvidia"]}
      
      The chart already tolerates the nvidia.com/gpu:NoSchedule taint.
    • Sharing (optional). To let several pods share the card, add a time-slicing config under config.map and name it in config.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.

  2. 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/gpu shows 1 under Capacity and Allocatable (or the number of time-slicing replicas).
  • The pod requesting the GPU is Running, and kubectl exec <pod> -- nvidia-smi prints the full table.
  • A new container shows the capped limits: kubectl exec <pod> -- sh -c 'ulimit -Sn; ulimit -Hn' gives 1024 and 524288.

Troubleshooting

  • nvidia-smi fails after the reboot: check dkms status (headers) and Secure Boot (mokutil --sb-state).
  • Pods Pending with Insufficient 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 default runc runtime, which can't see the GPU. Make the NVIDIA runtime the default (step 5), or give the plugin a RuntimeClass that uses it.
  • config.toml still says default_runtime_name = "runc" after step 5: look at containerd config dump before 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. Run kubectl from the admin workstation, or deploy the plugin through GitOps.
  • The GPU is already taken: each nvidia.com/gpu goes to one container at a time. A second pod requesting it stays Pending until 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-smi in a container freezes the node, but nvidia-smi -L works: it's memory, not the GPU. Check ulimit -Hn in the container: about a billion means containerd still has LimitNOFILE=infinity (end of step 6). The kernel log shows Out of memory: Killed process … (nvidia-smi) when the OOM killer wins the race.
  • nvidia-smi --query-gpu=persistence_mode says Disabled although nvidia-persistenced runs: query it as root; an unprivileged user gets Disabled.
  • 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-smi at 0 % during playback can be right: a client that plays the codec itself gets the video copied, not transcoded.
  • h264_nvenc fails 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