Skip to content
GPU infrastructure on Kubernetes · Chapter 18 of 19 Appendix A: Cheat sheet

Appendix A: Cheat sheet

The most important commands, YAML snippets, numbers and pitfalls from Days 0 to 15. The days are in parentheses. Names are the ones from the lab: gpu-worker2 is the GPU node with Mokka, gpu-worker a node without a GPU.

Component Version Day
kind / Kubernetes (kindest/node) / Helm v0.33.0 / v1.37.0 / v4.3.2 0
Mokka (nvml-mock) 0.7.0 0
Node Feature Discovery / Device Plugin and GFD (chart nvidia-device-plugin) 0.19.0 / 0.18.2 2, 3
GPU Operator v26.3.3 7
DRA driver (dra-driver-nvidia-gpu) 0.5.1 8
Kueue 0.20.7 10
kube-prometheus-stack 93.9.0 12
Ollama / model 0.40.17 / qwen2.5:0.5b 14

GPU in the Pod, Device Plugin, Labels (Days 0 to 3)

kubectl get node gpu-worker2 -o jsonpath='{.status.allocatable}{"\n"}'
kubectl -n tag02 exec eine -- nvidia-smi -L
kubectl -n tag01 exec alle -- nvidia-smi \
  --query-gpu=index,memory.used,utilization.gpu,temperature.gpu --format=csv | head -3
kubectl -n tag02 exec eine -- printenv NVIDIA_VISIBLE_DEVICES
kubectl describe node gpu-worker2 | sed -n '/Allocated resources/,/Events/p' | grep nvidia
kubectl get nodes -o custom-columns='NAME:.metadata.name,CAP:.status.capacity.nvidia\.com/gpu,ALLOC:.status.allocatable.nvidia\.com/gpu'
kubectl get node gpu-worker2 -o json | jq -r '.metadata.labels | to_entries[]
  | select(.key|startswith("nvidia.com")) | "\(.key)=\(.value)"' | grep -v timestamp
  nodeSelector:
    nvidia.com/gpu.product: NVIDIA-T4
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 1
Rule or label Meaning
GPUs go under limits requests alone is rejected, requests takes the value of limits (Day 2)
whole numbers only 500m is invalid, no overcommitting, more than available means Pending
Device Plugin gone running Pods keep computing, no new GPU Pod starts (Day 2)
feature.node.kubernetes.io/pci-10de.present NFD, 10de is NVIDIA’s PCI vendor ID (Day 3)
nvidia.com/gpu.product, gpu.memory, gpu.count GFD, also usable for nodeAffinity with operator: Gt (Day 3)

Taints and Reservation (Day 4)

kubectl taint node gpu-worker2 nvidia.com/gpu=present:NoSchedule
kubectl get nodes -o custom-columns='NODE:.metadata.name,TAINTS:.spec.taints[*].key'
kubectl get priorityclass gpu-produktion gpu-training -o custom-columns=NAME:.metadata.name,VALUE:.value,POLICY:.preemptionPolicy
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule

NoSchedule keeps new Pods without a toleration away, running ones stay. A toleration allows the node, it does not force it. Your own DaemonSets such as the NFD worker need it too. A PriorityClass with preemptionPolicy: Never waits and preempts no one.

Time-Slicing and MIG (Days 5, 6)

version: v1
flags:
  migStrategy: none
sharing:
  timeSlicing:
    renameByDefault: true
    failRequestsGreaterThanOne: true
    resources:
    - name: nvidia.com/gpu
      replicas: 4
kubectl -n kube-system create configmap gpu-sharing --from-file=config.yaml=time-slicing.yaml \
  --dry-run=client -o yaml | kubectl replace -f -
kubectl -n kube-system rollout restart ds/nvidia-device-plugin-mock
kubectl get node gpu-worker2 -o jsonpath='{.metadata.labels.nvidia\.com/gpu\.replicas} {.metadata.labels.nvidia\.com/gpu\.sharing-strategy} {.metadata.labels.nvidia\.com/gpu\.product}{"\n"}'
kubectl -n tag06 exec admin -- nvidia-smi mig -lgip -i 0
kubectl get node gpu-worker2 -o json | jq '.status.allocatable | with_entries(select(.key|startswith("nvidia.com/mig")))'
Option Effect
replicas: 4 each GPU appears four times in allocatable, the Pods see the same UUID
failRequestsGreaterThanOne Pods requesting more than one shared GPU are rejected
renameByDefault shared GPUs are called nvidia.com/gpu.shared
MIG single each instance as nvidia.com/gpu, all instances on a node the same size
MIG mixed a separate resource per size, e.g. nvidia.com/mig-3g.20gb

Time-slicing separates neither memory nor faults. MIG separates in hardware: 1g.5gb is one seventh of the compute with 5 GB, 3g.20gb three sevenths with 20 GB. Device Plugin and GFD need the same configuration, otherwise the labels lie.

GPU Operator and ClusterPolicy (Day 7)

kubectl get clusterpolicy
kubectl patch clusterpolicy cluster-policy --type=merge \
  -p '{"spec":{"devicePlugin":{"config":{"name":"time-slicing-config","default":"a100-geteilt"}}}}'
kubectl label node gpu-worker2 nvidia.com/device-plugin.config=a100-ganz --overwrite
kubectl -n gpu-operator logs ds/nvidia-device-plugin-daemonset -c config-manager | grep "updated to config" | tail -1
P=$(kubectl -n gpu-operator get pod -l app=nvidia-operator-validator -o name)
kubectl -n gpu-operator logs $P -c nvidia-operator-validator --tail=1

Never change operands directly: the operator overwrites the change at the next reconciliation. The state belongs in the ClusterPolicy, per-node differences in the label nvidia.com/device-plugin.config.

DRA (Days 8, 9)

kubectl get deviceclass
kubectl get resourceslice -o json | jq '[.items[].spec.devices[]] | length'
kubectl -n tag08 get resourceclaim
kubectl -n tag08 get resourceclaim eine-gpu -o jsonpath='{.status.allocation.devices.results}{"\n"}{.status.reservedFor}{"\n"}'
kubectl get deviceclass gpu.nvidia.com -o jsonpath='{.spec.extendedResourceName}{"\n"}'
kubectl patch deviceclass gpu.nvidia.com --type merge -p '{"spec":{"extendedResourceName":"nvidia.com/gpu"}}'
apiVersion: resource.k8s.io/v1
kind: ResourceClaim
metadata:
  name: eine-gpu
  namespace: tag08
spec:
  devices:
    requests:
    - name: gpu
      exactly:
        deviceClassName: gpu.nvidia.com
    resources:
      claims:
      - name: gpu
  resourceClaims:
  - name: gpu
    resourceClaimName: eine-gpu
Term Meaning
ResourceSlice a driver’s devices on a node, no kubelet plugin means no slices
allocationMode: ExactCount, count: several GPUs in one claim (Day 8)
resourceClaimTemplateName instead of resourceClaimName: each Pod of a Deployment gets its own claim (Day 9)
selectors: - cel: e.g. device.attributes["gpu.nvidia.com"].productName.startsWith("NVIDIA H100")
compareTo(quantity("40Gi")) >= 0 quantities are compared with compareTo, not with >=
firstAvailable priority list instead of exactly, the scheduler takes the first one that fits
extendedResourceName translates limits: nvidia.com/gpu into a claim, the node then reports 0 nvidia.com/gpu

Kueue (Days 10, 11, 15)

kind: ResourceFlavor
metadata:
  name: a100
spec:
  nodeLabels:
    nvidia.com/gpu.product: NVIDIA-A100-SXM4-40GB
kubectl get cq
kubectl get workloads -A
w=$(kubectl -n training get workloads -o name | grep riesig)
kubectl -n training get $w -o jsonpath='{range .status.conditions[?(@.type=="QuotaReserved")]}{.message}{"\n"}{end}'
for t in training inferenz forschung; do kubectl patch cq $t --type=merge -p '{"spec":{"cohortName":"gpu","preemption":{"reclaimWithinCohort":"Any","withinClusterQueue":"LowerPriority"}}}'; done
kubectl get cq -o custom-columns=NAME:.metadata.name,BELEGT:.status.flavorsUsage[0].resources[2].total,GELIEHEN:.status.flavorsUsage[0].resources[2].borrowed,WARTEND:.status.pendingWorkloads
kubectl patch clusterqueue forschung --type merge -p '{"spec":{"stopPolicy":"None"}}'
W=$(kubectl -n training get workload -o name | grep probe)
kubectl -n training patch $W --type merge -p '{"spec":{"active":false}}'
Component Purpose
Label kueue.x-k8s.io/queue-name: gpu the job goes through the LocalQueue gpu, without the label it bypasses Kueue
ResourceFlavor on admission, Kueue writes the nodeLabels into the job as a nodeSelector
ClusterQueue, nominalQuota a team’s quota per flavor and resource, e.g. 4 nvidia.com/gpu
cohortName, borrowingLimit borrowing between teams and its limit (Day 11)
reclaimWithinCohort: Any the lender gets its GPUs back through preemption
WorkloadPriorityClass, label kueue.x-k8s.io/priority-class rank within a team
stopPolicy: Hold / HoldAndDrain no new workloads / also preempt running ones (Day 15)
Workload spec.active: false withdraw the admission, Kueue restores the template (Day 15)

Monitoring (Days 12, 13)

kubectl patch clusterpolicy cluster-policy --type=merge -p '{"spec":{"dcgmExporter":{"serviceMonitor":{"enabled":true,"interval":"15s"}}}}'
kubectl -n monitoring port-forward svc/monitoring-kube-prometheus-prometheus 9090:9090 >/dev/null 2>&1 &
curl -s localhost:9090/api/v1/targets | jq -r '.data.activeTargets[] | .labels.job + " " + .health' | sort | uniq -c
curl -s localhost:9090/api/v1/query --data-urlencode 'query=count(DCGM_FI_DEV_GPU_UTIL)' | jq -r '.data.result[0].value[1]'
curl -s localhost:9090/api/v1/rules | jq -r '.data.groups[] | select(.name=="gpu-ausfall") | .rules[] | .name + " " + .state'
Question PromQL
utilization now / averaged over 5 minutes DCGM_FI_DEV_GPU_UTIL / avg_over_time(DCGM_FI_DEV_GPU_UTIL[5m])
free memory per model (GiB) sum by (modelName) (DCGM_FI_DEV_FB_FREE) / 1024
node power draw / hottest GPU sum(DCGM_FI_DEV_POWER_USAGE) / max(DCGM_FI_DEV_GPU_TEMP)
memory used (fraction) DCGM_FI_DEV_FB_USED / (DCGM_FI_DEV_FB_USED + DCGM_FI_DEV_FB_FREE)
which Xids count by (Hostname, err_code, err_msg) (DCGM_FI_DEV_XID_ERRORS)
    - alert: GPUXidFehler
      expr: DCGM_FI_DEV_XID_ERRORS > 0
    - alert: GPUMesswerteFehlen
      expr: absent(DCGM_FI_DEV_GPU_UTIL{Hostname="gpu-worker2"})
      for: 1m

DCGM_FI_DEV_FB_USED_BYTES does not exist, the metric is called DCGM_FI_DEV_FB_USED (MiB). health=ok only means the rule can be evaluated. absent() fires only after the 5-minute lookback plus for (Day 15). The GPU Operator manages the ServiceMonitor, it is switched on and off in the ClusterPolicy.

GPU Failures (Day 13)

Xid Meaning
48 double-bit error in memory (Double Bit ECC)
63/64 spare rows for defective memory
79 “GPU has fallen off the bus”: the GPU has disappeared from the PCIe bus
94/95 memory errors, contained or not

Mokka simulates the modes ecc_uncorrectable, lost and fallen_off_bus, and healthy goes back:

helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 -n mokka --reuse-values --set gpu.failureInjection.enabled=true --set gpu.failureInjection.mode=ecc_uncorrectable --set gpu.failureInjection.after_calls=1 --set gpu.failureInjection.xid.code=79 >/dev/null
kubectl -n mokka rollout restart ds/nvml-mock
helm -n mokka get values nvml-mock -o json | jq -c '.gpu.failureInjection'
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 -n mokka --reuse-values --set gpu.failureInjection.enabled=false --set gpu.failureInjection.mode=healthy --set gpu.failureInjection.after_calls=0 --set gpu.failureInjection.xid.code=0 >/dev/null

The procedure: cordon, drain, repair, verify, only then uncordon.

kubectl cordon gpu-worker2
kubectl drain gpu-worker2 --ignore-daemonsets --delete-emptydir-data --force --timeout=90s 2>&1 | grep -E 'evicting|evicted|drained'
P=$(kubectl -n gpu-operator get pod -l app=nvidia-operator-validator -o name)
kubectl -n gpu-operator logs $P -c nvidia-operator-validator --tail=1
kubectl get resourceslice -o json | jq '[.items[].spec.devices[]] | length'
kubectl uncordon gpu-worker2
kubectl get node gpu-worker2 -o jsonpath='{.spec.unschedulable}{"\n"}'

drain needs --force only for bare Pods without a controller. After draining, Kueue still treats the workloads as admitted, the quota stays occupied (Day 15).

Model on the Cluster (Day 14)

kubectl -n tag14 exec deploy/modell -- ollama pull qwen2.5:0.5b >/dev/null
kubectl -n tag14 logs deploy/modell 2>&1 | grep 'inference compute' | cut -c1-200

Rule of thumb for model memory: file size plus context memory plus runtime, a good 1 GB for the 397 MB model. 7 billion parameters at 16 bits are 14 GB plus context: fits on an A100 with 40 GB, not on a T4 with 16 GB. Limit too small: OOMKilled, exit code 137. Every change to the Deployment brings a new Pod with an empty emptyDir, and the model is gone.

Failure Pattern and Cause (Day 15)

Failure pattern Cause Look here first
new GPU jobs Pending, cannot allocate all claims DRA kubelet plugin not running, no ResourceSlices kubectl get resourceslice, kubectl -n nvidia-dra get ds
a team’s jobs stay Suspended ClusterQueue with stopPolicy: Hold workload conditions, kubectl get clusterqueue
alert GPUXidFehler GPU failure (Xid 48, 79 …) PromQL on DCGM_FI_DEV_XID_ERRORS, then the procedure from Day 13
GPUMesswerteFehlen, exporter running ServiceMonitor switched off in the ClusterPolicy Prometheus targets, kubectl get servicemonitor -A
Insufficient nvidia.com/gpu, GPUs free extendedResourceName missing from the DeviceClass DeviceClass, ResourceSlices
admitted, Pod Pending wrong nodeLabels in the ResourceFlavor the Pod’s nodeSelector, ResourceFlavor

The Pitfalls from the Book

Pitfall Day
MIG single in the normal plugin DaemonSet: crash because /proc/driver/nvidia-caps/mig-minors is missing 6
Mokka simulates NVML, not CUDA: Ollama computes on the CPU even with a Mokka GPU 14
helm upgrade --reuse-values does not repair drift, kubectl rollout undo does 15
A repaired flavor only helps workloads admitted afterwards 15

Contents

More