Home / AI & GenAI

AI & GenAICheat sheetAdvanced

Kubernetes Dynamic Resource Allocation (DRA) cheat sheet for GPUs: claims, CEL selectors, fallbacks and debugging

Request GPUs by attribute with DRA. ResourceClaim and template YAML, CEL selectors, prioritized fallbacks, sharing, admin access, and how to debug claims that never allocate.

Deepak Bhardwaj7 min read

Applies toKubernetes 1.34+ (resource.k8s.io/v1), NVIDIA DRA driver for GPUs; sub-features vary by version

You need "any GPU with at least 40 GiB", "two GPUs on the same PCIe root", or "an A100, else two smaller cards". The device plugin only understands a count of nvidia.com/gpu, so people fall back to node labels and separate pools. DRA lets the scheduler match devices by attribute. Use this page when writing or debugging claims.

Warning

Check driver support before production use. At the time of writing, the NVIDIA DRA driver documents ComputeDomains as officially supported, while GPU allocation is available to try but disabled by default in its Helm chart. Re-read the driver README for your version.

The objects

Object Created by Purpose
DeviceClass Driver or admin Named category, with default selectors and config
ResourceSlice Driver, per node Inventory: devices, attributes, capacity
ResourceClaim You, or from a template A request and its allocation result
ResourceClaimTemplate You Creates one claim per pod

Pick by lifetime: a template gives each pod its own devices, deleted with the pod. A named claim outlives pods, and pods that reference it share the same devices.

Check the cluster

kubectl api-resources --api-group=resource.k8s.io
kubectl get deviceclass
kubectl get resourceslice -o wide
kubectl get resourceclaim -A
kubectl get pods -A | grep -i dra

With the NVIDIA driver, expect classes such as gpu.nvidia.com and mig.nvidia.com. Dump what a node really advertises before writing any selector:

kubectl get resourceslice -o json | jq '
  .items[] | select(.spec.driver=="gpu.nvidia.com")
  | {node: .spec.nodeName, pool: .spec.pool,
     devices: [.spec.devices[] | {name, attributes, capacity}]}'

Attribute names belong to the driver, not to Kubernetes. Current NVIDIA GPU attributes include type, uuid, productName, brand, architecture, driverVersion and cudaComputeCapability. Verify in your own output.

Install notes for the NVIDIA driver

helm install dra-driver-nvidia-gpu \
  oci://registry.k8s.io/dra-driver-nvidia/charts/dra-driver-nvidia-gpu \
  --version <chart-version> \
  --namespace dra-driver-nvidia-gpu --create-namespace \
  --set gpuResourcesEnabledOverride=true \
  --set nvidiaDriverRoot=/run/nvidia/driver   # when the GPU Operator manages the driver

nvidiaDriverRoot defaults to /, for drivers installed on the host. A wrong value is a common cause of a kubelet plugin that starts with no devices. CDI must be enabled in the container runtime; it is on by default in containerd 2.0+ and CRI-O 1.27+.

Caution

Don't let the classic device plugin and DRA hand out the same GPU. They keep separate accounts, so both can allocate one card. Disable the device plugin on DRA nodes, or separate the nodes by pool, taint and daemonset selector. Drain GPU pods before switching a node over.

Request patterns

One GPU per pod, by memory

apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata: {name: gpu-40g, namespace: inference}
spec:
  spec:
    devices:
      requests:
      - name: gpu
        exactly:
          deviceClassName: gpu.nvidia.com
          count: 1
          selectors:
          - cel:
              expression: >-
                device.capacity["gpu.nvidia.com"].memory
                .compareTo(quantity("40Gi")) >= 0
---
apiVersion: v1
kind: Pod
metadata: {name: vllm, namespace: inference}
spec:
  resourceClaims:
  - name: gpu
    resourceClaimTemplateName: gpu-40g
  containers:
  - name: vllm
    image: vllm/vllm-openai:<pinned-tag>
    args: ["--model", "/models/m"]
    resources:
      claims:
      - name: gpu

Two references are required: spec.resourceClaims attaches the claim to the pod, and resources.claims exposes it to the container. Forgetting the second gives a running pod with no GPU.

Reported capacity is rarely the marketing number. A "40 GB" card can report less than 40Gi, so read the slice first.

Useful CEL expressions

# product match
device.attributes["gpu.nvidia.com"].productName.lowerAscii().contains("a100")

# minimum driver version
device.attributes["gpu.nvidia.com"].driverVersion.compareTo(semver("570.0.0")) >= 0

# full GPUs only
device.attributes["gpu.nvidia.com"].type == "gpu"

# MIG profile (class mig.nvidia.com, check your slice for the name)
device.attributes["gpu.nvidia.com"].profile == "1g.10gb"

Reading a missing attribute is a CEL runtime error, which fails allocation rather than skipping that device. On mixed fleets, guard it:

"architecture" in device.attributes["gpu.nvidia.com"] &&
device.attributes["gpu.nvidia.com"].architecture == "Hopper"

Fallback order

firstAvailable tries subrequests in order. Use it instead of exactly:

requests:
- name: gpu
  firstAvailable:
  - name: big
    deviceClassName: gpu.nvidia.com
    selectors:
    - cel: {expression: 'device.capacity["gpu.nvidia.com"].memory.compareTo(quantity("70Gi")) >= 0'}
  - name: two-small
    deviceClassName: gpu.nvidia.com
    count: 2
    selectors:
    - cel: {expression: 'device.capacity["gpu.nvidia.com"].memory.compareTo(quantity("35Gi")) >= 0'}

The application must adapt to whichever result it gets. For vLLM, derive the tensor parallel size at start:

exec vllm serve /models/m --tensor-parallel-size "$(nvidia-smi -L | grep -c '^GPU')"

That count suits full GPUs; MIG devices list differently.

Devices that must match

devices:
  requests:
  - name: gpus
    exactly: {deviceClassName: gpu.nvidia.com, count: 2}
  constraints:
  - requests: ["gpus"]
    matchAttribute: gpu.nvidia.com/productName

matchAttribute needs the domain prefix, and every device must have the attribute with the same value. If your slices publish resource.kubernetes.io/pcieRoot, it can align a GPU with a NIC across drivers.

Share one GPU between pods

Create a ResourceClaim, and reference it from each pod with resourceClaimName:

resourceClaims:
- name: gpu
  resourceClaimName: shared-gpu

All those pods must run where the device is, so they land on one node. A claim allows up to 256 reservations. Sharing a claim gives no memory isolation: one vLLM with a high --gpu-memory-utilization starves the others.

Monitoring access

adminAccess: true gives access to devices already allocated to someone else. It needs the DRAAdminAccess feature and a namespace labelled for it.

kubectl label namespace gpu-monitoring resource.kubernetes.io/admin-access=true

Caution

Admin access bypasses allocation. Restrict who can label namespaces, or any tenant can reach another tenant's GPU. The label key changed during beta, so check the API docs for your version.

Debug a claim that doesn't allocate

NS=inference; POD=vllm
kubectl -n $NS describe pod $POD | sed -n '/Events/,$p'
kubectl -n $NS get pod $POD -o jsonpath='{.status.resourceClaimStatuses}{"\n"}'
CLAIM=$(kubectl -n $NS get pod $POD -o jsonpath='{.status.resourceClaimStatuses[0].resourceClaimName}')
kubectl -n $NS get resourceclaim $CLAIM -o json | jq '.status | {allocation, reservedFor}'
State Meaning Next check
No claim object Template missing or misnamed Namespace, resourceClaimTemplateName, controller-manager logs
Claim exists, no allocation Nothing matches, or all in use Slice dump, CEL expression, other claims
Pod event with a CEL error Attribute missing or wrong type Add an in guard
Allocated, pod in ContainerCreating Kubelet couldn't prepare the device DRA plugin pod on that node, CDI
Running, no GPU in container Claim not in resources.claims Container spec
Claim stuck deleting Still reserved by a pod status.reservedFor

Who holds the devices on a node:

kubectl get resourceclaim -A -o json | jq -r '
  .items[] | . as $c | .status.allocation.devices.results[]?
  | [.driver, .pool, .device, $c.metadata.namespace, $c.metadata.name,
     ([$c.status.reservedFor[]?.name] | join(","))] | @tsv'

Node-side logs:

kubectl -n dra-driver-nvidia-gpu get pods -o wide
kubectl -n dra-driver-nvidia-gpu logs <kubelet-plugin-pod> --all-containers --tail=200
journalctl -u kubelet --since "-15 min" | grep -i -E 'resourceclaim|dra'

Warning

Don't remove a finalizer from a claim to unblock deletion until you have confirmed that no process on the node still uses the GPU. Removing it early lets the scheduler allocate a device that is still busy.

Operational traps

  • Quota: a ResourceQuota on requests.nvidia.com/gpu doesn't limit DRA claims. Quota by device class uses the <class>.deviceclass.resource.k8s.io/devices form.
  • Autoscaling: the cluster autoscaler has to simulate slices for nodes that don't exist. Test scale-from-zero before migrating a pool.
  • Immutable specs: a claim's spec can't be edited. Change the template and roll the pods.
  • Dashboards: views built on allocatable nvidia.com/gpu read zero on DRA nodes. Use the holder query above.

Prevent it next time

  • Store a slice dump per node type in Git, and test CEL expressions against it when the driver changes.
  • Publish a few approved templates instead of letting each team write selectors.
  • Migrate one pool at a time, and keep a device-plugin pool until rollback has been rehearsed.