Day 3: Node Feature Discovery and GPU Feature Discovery
Goal: Have GPU nodes detected and labeled automatically, and schedule Pods by GPU model, memory and architecture · Duration: approx. 60 min · Prerequisite: Day 2
Briefing
- So far you have labeled the GPU node by hand
(
gpu=mokka). In a cluster with many nodes and several GPU models, nobody does that by hand. - Node Feature Discovery (NFD, a Kubernetes SIG
project) reads the hardware features of each node and writes them as
labels: CPU instruction sets, kernel, PCI devices. NFD recognizes an
NVIDIA card by its PCI vendor ID
10de. - GPU Feature Discovery (GFD, from NVIDIA) asks for more detail via NVML: model, memory, architecture, driver and CUDA version, MIG capability.
- Neither writes labels directly; both write feature files. NFD reads them and sets the labels from them. Mokka plays the role of the hardware here: it writes the file that would come from the PCI bus on a real server.
Mokka agent ─▶ features.d/nvml-mock.features (pci-10de.present=true) ─┐
GFD (NVML) ─▶ features.d/gfd (gpu.product=…, gpu.memory=…) ├─▶ NFD ─▶ node labels
NFD itself ─▶ CPU, Kernel, … ┘
Drill 1: Node Feature Discovery
mkdir -p ~/gpu/tag03 && cd ~/gpu/tag03
kubectl get nodes -o custom-columns='NODE:.metadata.name,PCI_10DE:.metadata.labels.feature\.node\.kubernetes\.io/pci-10de\.present'
helm repo add nfd https://kubernetes-sigs.github.io/node-feature-discovery/charts
helm repo update
helm upgrade --install nfd nfd/node-feature-discovery --namespace node-feature-discovery \
--create-namespace --version 0.19.0 --wait --timeout 180s
kubectl -n node-feature-discovery get pods -o wide | cut -c1-78Expected (shortened):
NODE PCI_10DE
gpu-control-plane <none>
gpu-worker <none>
gpu-worker2 <none>
...
STATUS: deployed
NAME READY STATUS RESTARTS AGE
nfd-node-feature-discovery-gc-6b89b8d7b9-n7xsg 1/1 Running 0 45s
nfd-node-feature-discovery-master-5fbbb7cf74-6qb6t 1/1 Running 0 45s
nfd-node-feature-discovery-worker-82s7f 1/1 Running 0 46s
nfd-node-feature-discovery-worker-zdqhq 1/1 Running 0 46s
One worker per node without a taint, one master that writes the labels, and a garbage collector. After about half a minute:
kubectl get nodes -o custom-columns='NODE:.metadata.name,PCI_10DE:.metadata.labels.feature\.node\.kubernetes\.io/pci-10de\.present'Expected:
NODE PCI_10DE
gpu-control-plane <none>
gpu-worker <none>
gpu-worker2 true
Save your progress? Sign up for free
Drill 2: How NFD Knows
On Day 0 you saw that there is no NVIDIA PCI device on
gpu-worker2. NFD got the information from a feature file
that Mokka creates:
kubectl -n mokka exec daemonset/nvml-mock -c node-agent -- \
cat /host/etc/kubernetes/node-feature-discovery/features.d/nvml-mock.featuresExpected:
pci-10de.present=true
On real hardware, the same label comes from NFD’s PCI scan. The file route is the official way for custom features. How many labels NFD manages in total, and which ones:
kubectl get node gpu-worker2 \
-o jsonpath='{.metadata.annotations.nfd\.node\.kubernetes\.io/feature-labels}' \
| tr ',' '\n' | wc -l
kubectl get node gpu-worker2 -o json | jq -r '.metadata.labels | keys[]' \
| grep feature.node | head -4Expected:
47
feature.node.kubernetes.io/cpu-cpuid.ADX
feature.node.kubernetes.io/cpu-cpuid.AESNI
feature.node.kubernetes.io/cpu-cpuid.AVX
feature.node.kubernetes.io/cpu-cpuid.AVX2
47 labels, most of them about the CPU. The
feature-labels annotation lists what belongs to NFD. Labels
you set by hand do not appear there.
Save your progress? Sign up for free
Drill 3: GPU Feature Discovery
GFD is part of the device plugin’s Helm chart. You already have the device plugin, so you only switch on GFD:
helm repo add nvdp https://nvidia.github.io/k8s-device-plugin
helm repo update
cat > gfd-werte.yaml <<EOF
devicePlugin:
enabled: false
gfd:
enabled: true
nfd:
enabled: false
nvidiaDriverRoot: /var/lib/nvml-mock/driver
podAnnotations:
nvml-mock.nvidia.com/devices: "true"
EOF
helm upgrade --install gfd nvdp/nvidia-device-plugin --version 0.18.2 \
--namespace gpu-feature-discovery --create-namespace -f gfd-werte.yaml \
--wait --timeout 180s
kubectl -n gpu-feature-discovery get dsExpected (shortened):
STATUS: deployed
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
gfd-nvidia-device-plugin-gpu-feature-discovery 1 1 1 1 1 <none> 30s
nfd.enabled: false: the chart would bring its own NFD, and you already have one.nvidiaDriverRoot: the driver root from Day 0.- The annotation gives GFD all GPUs via Mokka so it can query them via NVML. On real servers it is unnecessary.
NODE SELECTOR <none>, and still GFD runs on only
one node. The chart sets a node affinity on
feature.node.kubernetes.io/pci-10de.present=true, the label
from Drill 1. Without NFD, GFD would stay at DESIRED 0,
like the device plugin on Day 2.
kubectl -n gpu-feature-discovery logs ds/gfd-nvidia-device-plugin-gpu-feature-discovery \
| grep -E "Using NVML|Writing labels" | cut -c1-110Expected:
I1122 11:04:07.266380 1 factory.go:58] Using NVML manager
I1122 11:04:08.290736 1 output.go:82] Writing labels to output file /etc/kubernetes/node-feature-discove
Save your progress? Sign up for free
Drill 4: The GPU Labels
kubectl get node gpu-worker2 -o json | jq -r '.metadata.labels | to_entries[]
| select(.key|startswith("nvidia.com")) | "\(.key)=\(.value)"' | grep -v timestampExpected:
nvidia.com/cuda.driver-version.full=580.65.06
nvidia.com/cuda.driver-version.major=580
nvidia.com/cuda.driver-version.minor=65
nvidia.com/cuda.driver-version.revision=06
nvidia.com/cuda.driver.major=580
nvidia.com/cuda.driver.minor=65
nvidia.com/cuda.driver.rev=06
nvidia.com/cuda.runtime-version.full=13.0
nvidia.com/cuda.runtime-version.major=13
nvidia.com/cuda.runtime-version.minor=0
nvidia.com/cuda.runtime.major=13
nvidia.com/cuda.runtime.minor=0
nvidia.com/gpu.compute.major=8
nvidia.com/gpu.compute.minor=0
nvidia.com/gpu.count=8
nvidia.com/gpu.family=ampere
nvidia.com/gpu.machine=NVIDIA-A100-SXM4-40GB
nvidia.com/gpu.memory=40960
nvidia.com/gpu.mode=compute
nvidia.com/gpu.product=NVIDIA-A100-SXM4-40GB
nvidia.com/gpu.replicas=1
nvidia.com/gpu.sharing-strategy=none
nvidia.com/mig.capable=true
nvidia.com/mps.capable=false
nvidia.com/vgpu.present=false
| Label | Used for |
|---|---|
gpu.product |
GPU model, spaces replaced by - |
gpu.memory |
Memory per GPU in MiB |
gpu.compute.major |
Architecture generation (8 = Ampere, 9 = Hopper) |
cuda.driver.major |
Driver version, important for matching CUDA images |
mig.capable |
Whether the GPU can be split into MIG instances (Day 6) |
gpu.replicas, gpu.sharing-strategy |
Whether and how GPUs are shared (Day 5) |
Save your progress? Sign up for free
Drill 5: Scheduling by Model and Memory
Two Pods: one wants a T4, the other wants at least 32 GB of memory and an architecture of Ampere or newer.
kubectl create namespace tag03
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: will-t4
namespace: tag03
spec:
nodeSelector:
nvidia.com/gpu.product: Tesla-T4
containers:
- name: c
image: ubuntu:24.04
command: [sleep, infinity]
resources:
limits:
nvidia.com/gpu: 1
---
apiVersion: v1
kind: Pod
metadata:
name: will-viel-speicher
namespace: tag03
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: nvidia.com/gpu.memory
operator: Gt
values: ["32000"]
- key: nvidia.com/gpu.compute.major
operator: Gt
values: ["7"]
containers:
- name: c
image: ubuntu:24.04
command: [sleep, infinity]
resources:
limits:
nvidia.com/gpu: 1
EOF
sleep 8
kubectl -n tag03 get pods -o wide | cut -c1-80
kubectl -n tag03 get events --field-selector involvedObject.name=will-t4 \
-o jsonpath='{.items[0].message}{"\n"}'Expected:
pod/will-t4 created
pod/will-viel-speicher created
NAME READY STATUS RESTARTS AGE IP NODE
will-t4 0/1 Pending 0 8s <none> <none>
will-viel-speicher 1/1 Running 0 8s 10.244.2.13 gpu-worker2
0/3 nodes are available: 1 node(s) had untolerated taint(s), 2 node(s) didn't match
Pod's node affinity/selector. preemption: 0/3 nodes are available: 3 Preemption is not
helpful for scheduling.
Gt compares label values as numbers. That way a team
writes “at least 32 GB” without listing every model, and still runs on
an H100 tomorrow.
kubectl -n tag03 delete pod will-viel-speicherSave your progress? Sign up for free
Exercise: Speed Drills
- Show the GPU model and memory of all nodes in one table. Target time: 1 min
- Show on which nodes NFD found an NVIDIA PCI device. Target time: 1 min
- Show the major driver version of the GPU node. Target time: 30 s
Solution
kubectl get nodes -o custom-columns='NODE:.metadata.name,PRODUCT:.metadata.labels.nvidia\.com/gpu\.product,MEM:.metadata.labels.nvidia\.com/gpu\.memory'
kubectl get nodes -l feature.node.kubernetes.io/pci-10de.present=true
kubectl get node gpu-worker2 -o jsonpath='{.metadata.labels.nvidia\.com/cuda\.driver\.major}{"\n"}'Save your progress? Sign up for free
Checkpoint
kubectl get nodes -l nvidia.com/gpu.product=NVIDIA-A100-SXM4-40GBExpected: exactly gpu-worker2.
kubectl get node gpu-worker2 -o jsonpath='{.metadata.labels.nvidia\.com/gpu\.count}{"\n"}'Expected: 8
Challenge
The Pod will-t4 is waiting. Turn the node into a T4 node
by switching the Mokka profile, and get the Pod running. Afterwards,
switch back to A100.
Hint: After the switch, check three things: the
label, the number in allocatable, and the exact label value
the Pod expects.
Solution
cd ~/gpu/tag00
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 \
-n mokka -f mokka-werte.yaml --set gpu.profile=t4 --wait --timeout 180s \
| grep -E "Profile|GPUs per node"Expected:
Profile: t4
GPUs per node: 4
GFD checks once a minute. After a good half minute:
kubectl get node gpu-worker2 -o jsonpath='{.metadata.labels.nvidia\.com/gpu\.product} {.metadata.labels.nvidia\.com/gpu\.count} {.status.allocatable.nvidia\.com/gpu}{"\n"}'
kubectl -n tag03 get pod will-t4Expected:
NVIDIA-T4 4 8
NAME READY STATUS RESTARTS AGE
will-t4 0/1 Pending 0 3m5s
Two surprises at once:
- The label is
NVIDIA-T4, notTesla-T4. The Pod is waiting for a value that will never exist. Always read label values from the real node, never from memory. - GFD reports 4 GPUs, the kubelet still offers 8. The device plugin counts the GPUs only at startup. After every hardware change, it needs a restart.
kubectl -n kube-system rollout restart ds/nvidia-device-plugin-mock
kubectl -n kube-system rollout status ds/nvidia-device-plugin-mock --timeout=120s
kubectl -n tag03 delete pod will-t4
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: will-t4
namespace: tag03
spec:
nodeSelector:
nvidia.com/gpu.product: NVIDIA-T4
containers:
- name: c
image: ubuntu:24.04
command: [sleep, infinity]
resources:
limits:
nvidia.com/gpu: 1
EOF
kubectl -n tag03 wait --for=condition=Ready pod/will-t4 --timeout=90s
kubectl -n tag03 exec will-t4 -- nvidia-smi --query-gpu=name,memory.total \
--format=csv,noheader
kubectl get node gpu-worker2 -o jsonpath='cap={.status.capacity.nvidia\.com/gpu} alloc={.status.allocatable.nvidia\.com/gpu}{"\n"}'Expected (shortened):
pod/will-t4 condition met
NVIDIA T4, 16384 MiB
cap=4 alloc=4
Back to A100 for the next days:
kubectl delete namespace tag03
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 \
-n mokka -f mokka-werte.yaml --wait --timeout 180s | grep Profile
kubectl -n kube-system rollout restart ds/nvidia-device-plugin-mock
kubectl -n kube-system rollout status ds/nvidia-device-plugin-mock --timeout=120s
sleep 70
kubectl get node gpu-worker2 -o jsonpath='alloc={.status.allocatable.nvidia\.com/gpu} product={.metadata.labels.nvidia\.com/gpu\.product}{"\n"}'Expected (shortened):
Profile: a100
alloc=8 product=NVIDIA-A100-SXM4-40GB
Save your progress? Sign up for free
Clean-up
Done in the challenge. NFD and GFD stay installed.
Interview Note
- What is the difference between NFD and GFD? NFD detects general features of a node (CPU, kernel, PCI devices); GFD queries the properties of the GPUs via NVML. GFD writes its results as a feature file, and NFD turns that into labels.
- How do you schedule “any GPU with at least 40 GB”?
With a node affinity on
nvidia.com/gpu.memoryand theGtoperator, instead of listing every model. - Why does a node show the wrong count after a GPU swap? Because the device plugin counts the GPUs at startup. After hardware changes, it has to restart.
Enterprise Note
- In mixed clusters, each GPU class additionally gets its own taint and its own team label (Day 4). The GFD labels alone describe the hardware, not who may use it.
- Workloads with a fixed model in the
nodeSelectorbreak with the next hardware purchase. Minimum requirements for memory and architecture are better. - The GPU Operator installs NFD and GFD along with it (Day 7). If you already run NFD for other purposes, switch off the bundled NFD, as done here in the chart.