Skip to content
GPU infrastructure on Kubernetes · Chapter 6 of 19 Day 4: Reserving GPU Nodes

Day 4: Reserving GPU Nodes

Goal: Keep regular workloads off GPU nodes, admit GPU workloads deliberately, and use PriorityClasses to decide who has to give way when capacity runs short · Duration: approx. 60 min · Prerequisite: Day 3

Briefing

  • A GPU node costs many times as much as a CPU node. If a web server that needs no GPU runs there, it takes up CPU and memory that a GPU Pod will be missing later.
  • Taint on the node: “Only those who are explicitly allowed.” Toleration in the Pod: “I am allowed.” A toleration permits, but it does not attract. Where a Pod should go is decided by nodeSelector, affinity or the requested resource itself.
  • PriorityClasses decide who wins when capacity runs short: a Pod with higher priority may evict Pods with lower priority (preemption). That way, production inference beats an experiment.
  • The infrastructure DaemonSets on the GPU node (Mokka, device plugin, NFD, GFD) also need a toleration. If you forget that, you only notice at the next restart.
Means Effect
Taint NoSchedule new Pods without a toleration do not land on the node, running ones stay
Taint NoExecute additionally, running Pods without a toleration are removed
Toleration permits the node, does not force it
PriorityClass order when capacity runs short, with or without preemption

Drill 1: The Web Server on the GPU Node

mkdir -p ~/gpu/tag04 && cd ~/gpu/tag04
kubectl create namespace tag04
kubectl -n tag04 create deployment web --image=nginx:1.29-alpine --replicas=6
kubectl -n tag04 rollout status deploy/web --timeout=120s
kubectl -n tag04 get pods -o custom-columns=NODE:.spec.nodeName --no-headers | sort | uniq -c
kubectl describe node gpu-worker2 | grep -i taints

Expected (shortened):

deployment "web" successfully rolled out
      3 gpu-worker
      3 gpu-worker2
Taints:             <none>

The scheduler spreads evenly. To it, gpu-worker2 is a node like any other, just with an extra resource.

Save your progress? Sign up for free

Drill 2: The Taint

The usual taint for GPU nodes is nvidia.com/gpu. The GPU Operator and many charts expect exactly this key.

kubectl taint node gpu-worker2 nvidia.com/gpu=present:NoSchedule
kubectl -n tag04 get pods -o custom-columns=NODE:.spec.nodeName --no-headers | sort | uniq -c

Expected:

node/gpu-worker2 tainted
      3 gpu-worker
      3 gpu-worker2

Nothing happens. NoSchedule only applies to new Pods. A new rollout creates new Pods:

kubectl -n tag04 rollout restart deploy/web
kubectl -n tag04 rollout status deploy/web --timeout=120s | tail -1
sleep 5
kubectl -n tag04 get pods -l app=web -o custom-columns=NODE:.spec.nodeName --no-headers \
  | sort | uniq -c

Expected:

deployment "web" successfully rolled out
      6 gpu-worker

All six on the CPU node. The GPU node is free for what it was bought for.

Save your progress? Sign up for free

Drill 3: The GPU Pod Now Needs a Toleration

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: gpu-ohne-toleration
  namespace: tag04
spec:
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 1
EOF
sleep 6
kubectl -n tag04 get pod gpu-ohne-toleration
kubectl -n tag04 get events --field-selector involvedObject.name=gpu-ohne-toleration \
  -o jsonpath='{.items[0].message}{"\n"}'

Expected:

pod/gpu-ohne-toleration created
NAME                  READY   STATUS    RESTARTS   AGE
gpu-ohne-toleration   0/1     Pending   0          6s
0/3 nodes are available: 1 Insufficient nvidia.com/gpu, 2 node(s) had untolerated
taint(s). preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling.

Read the message carefully: one node has no GPUs (gpu-worker), two have a taint the Pod does not tolerate (the control plane and gpu-worker2). With a toleration:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: gpu-mit-toleration
  namespace: tag04
spec:
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 1
EOF
kubectl -n tag04 wait --for=condition=Ready pod/gpu-mit-toleration --timeout=90s
kubectl -n tag04 get pod gpu-mit-toleration -o wide | cut -c1-80
kubectl -n tag04 delete pod gpu-ohne-toleration gpu-mit-toleration

Expected (shortened):

pod/gpu-mit-toleration condition met
NAME                 READY   STATUS    RESTARTS   AGE   IP            NODE
gpu-mit-toleration   1/1     Running   0          1s    10.244.2.24   gpu-worker2

Does every team have to write the toleration by hand? Kubernetes has the admission plugin ExtendedResourceToleration for that: it adds the toleration automatically to every Pod that requests nvidia.com/gpu. In kind, it is not enabled:

docker exec gpu-control-plane grep -o "enable-admission-plugins=[^ ]*" \
  /etc/kubernetes/manifests/kube-apiserver.yaml

Expected:

enable-admission-plugins=NodeRestriction

Save your progress? Sign up for free

Drill 4: Who Gives Way When Capacity Runs Short

Two classes: production may preempt, training waits and preempts nobody.

cat <<EOF | kubectl apply -f -
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: gpu-produktion
value: 100000
description: "Inferenz in Produktion – darf Trainings verdrängen"
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: gpu-training
value: 1000
preemptionPolicy: Never
description: "Training und Experimente – wartet, verdrängt niemanden"
EOF

Expected:

priorityclass.scheduling.k8s.io/gpu-produktion created
priorityclass.scheduling.k8s.io/gpu-training created

Two training runs occupy all eight GPUs:

for i in 1 2; do cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: training-$i
  namespace: tag04
  labels:
    team: forschung
spec:
  priorityClassName: gpu-training
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 4
EOF
done
kubectl -n tag04 wait --for=condition=Ready pod/training-1 pod/training-2 --timeout=120s
kubectl describe node gpu-worker2 | sed -n '/Allocated resources/,/Events/p' | grep nvidia

Expected (shortened):

pod/training-1 condition met
pod/training-2 condition met
  nvidia.com/gpu     8           8

Save your progress? Sign up for free

Drill 5: Inference Arrives

Caution: Preemption terminates Pods without asking. A bare Pod is gone afterwards; only a controller (Deployment, Job) creates it again.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: inferenz
  namespace: tag04
  labels:
    team: produkt
spec:
  priorityClassName: gpu-produktion
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 4
EOF
kubectl -n tag04 wait --for=condition=Ready pod/inferenz --timeout=120s
kubectl -n tag04 get pods -l 'team in (forschung,produkt)' \
  -o custom-columns=NAME:.metadata.name,PRIO:.spec.priority,STATUS:.status.phase
kubectl -n tag04 get events --sort-by=.lastTimestamp | grep Preempted | cut -c1-110

Expected:

pod/inferenz condition met
NAME         PRIO     STATUS
inferenz     100000   Running
training-1   1000     Running
33s         Normal    Preempted           pod/training-2              Preempted by pod 2fd5e4

The scheduler sacrificed one training run, exactly as many GPUs as needed. training-2 is gone; a bare Pod does not come back.

Save your progress? Sign up for free

Drill 6: Waiting Instead of Preempting

A new training run wants four GPUs. None is free:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: training-3
  namespace: tag04
  labels:
    team: forschung
spec:
  priorityClassName: gpu-training
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 4
EOF
sleep 6
kubectl -n tag04 get pod training-3
kubectl -n tag04 get events --field-selector involvedObject.name=training-3 \
  -o jsonpath='{.items[0].message}{"\n"}'

Expected:

pod/training-3 created
NAME         READY   STATUS    RESTARTS   AGE
training-3   0/1     Pending   0          7s
0/3 nodes are available: 1 node(s) had untolerated taint(s), 2 Insufficient
nvidia.com/gpu. preemption: not eligible due to preemptionPolicy=Never.

preemptionPolicy: Never: the training run gets in line at the back, even though it has the same priority as training-1. As soon as the inference is done, it moves up:

kubectl -n tag04 delete pod inferenz
kubectl -n tag04 wait --for=condition=Ready pod/training-3 --timeout=90s

Expected:

pod "inferenz" deleted from tag04 namespace
pod/training-3 condition met

Kueue automates exactly this behavior for entire teams on Days 10 and 11.

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Show all taints of all nodes. Target time: 1 min
  2. Show the priority and PriorityClass of all Pods in tag04. Target time: 1 min
  3. Show which DaemonSets in kube-system have a toleration for everything. Target time: 2 min

Solution

kubectl get nodes -o custom-columns='NODE:.metadata.name,TAINTS:.spec.taints[*].key'
kubectl -n tag04 get pods -o custom-columns='NAME:.metadata.name,CLASS:.spec.priorityClassName,PRIO:.spec.priority'
kubectl -n kube-system get ds -o json | jq -r '.items[] | select(any(.spec.template.spec.tolerations[]?; .operator=="Exists" and (.key==null))) | .metadata.name'

Save your progress? Sign up for free

Checkpoint

kubectl get node gpu-worker2 -o jsonpath='{.spec.taints[*].key}{"\n"}'

Expected: nvidia.com/gpu

kubectl get priorityclass gpu-produktion gpu-training -o custom-columns=NAME:.metadata.name,VALUE:.value,POLICY:.preemptionPolicy

Expected: gpu-produktion 100000 PreemptLowerPriority and gpu-training 1000 Never.

Challenge

A colleague restarts the NFD worker, “just to be safe”. What happens to the GPU node, and how do you fix it permanently?

Hint: Which DaemonSets on the GPU node have a toleration for nvidia.com/gpu?

Solution

kubectl -n node-feature-discovery rollout restart ds/nfd-node-feature-discovery-worker
sleep 20
kubectl -n node-feature-discovery get ds nfd-node-feature-discovery-worker

Expected:

NAME                                DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nfd-node-feature-discovery-worker   1         1         1       1            1           <none>          98m

DESIRED 1; before, it was 2. The new NFD worker is no longer allowed on gpu-worker2. The labels stay for now, but nobody reads the feature files from Mokka and GFD anymore. If the hardware changes, the cluster does not notice. The fix belongs in the Helm values, not in a patch:

cat > nfd-werte.yaml <<EOF
worker:
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
EOF
helm upgrade nfd nfd/node-feature-discovery -n node-feature-discovery --version 0.19.0 \
  -f nfd-werte.yaml --wait --timeout 180s | grep STATUS
kubectl -n node-feature-discovery get ds nfd-node-feature-discovery-worker

Expected:

STATUS: deployed
NAME                                DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nfd-node-feature-discovery-worker   2         2         2       2            2           <none>          99m

The device plugin and Mokka tolerate everything (operator: Exists without a key); GFD brings the toleration for nvidia.com/gpu with its chart. Only NFD had none.

Save your progress? Sign up for free

Clean-up

kubectl delete namespace tag04

The taint and the two PriorityClasses stay. From now on, every GPU Pod in the course needs the toleration.

Interview Note

  • Why is a taint alone not enough to get GPU Pods onto GPU nodes? A taint only keeps others away. GPU Pods land there because they request nvidia.com/gpu. Pods without a GPU request that should still go there additionally need a nodeSelector or an affinity.
  • What is the difference between NoSchedule and NoExecute? NoSchedule only affects new Pods; NoExecute also removes running Pods without a matching toleration, optionally after tolerationSeconds.
  • What does preemptionPolicy: Never do? The Pod gets its priority for the queue, but preempts nobody. Ideal for training runs that can wait.

Enterprise Note

  • In production, ExtendedResourceToleration sets the toleration automatically, and policies (Kyverno, ValidatingAdmissionPolicy) forbid high-priority PriorityClasses for all but approved namespaces.
  • Preemption without a controller loses work. Training runs therefore run as Jobs with checkpoints, so that preemption only costs time and not results.
  • Every Helm value set that runs on GPU nodes needs checking: is a toleration there? Otherwise the error from the challenge only surfaces months later at the next upgrade.

Contents

More