Skip to content

8.3. Devices (GPU Sharing)

When to Look at This

  • When deploying an application that uses a GPU
  • When a GPU pod does not move past Pending
  • When checking whether any GPUs are left
  • When checking whether several teams are sharing GPUs

Why GPUs Are Hard to Share

CPU and memory can be split into fractions. Requesting "0.5 CPU" lets the scheduler divide it for you.

GPUs are not like that.

CPU · memoryGPU
DividingCan be split into fractionsThe device is the basic unit
KindsNoneModels and memory sizes all differ
How to requestWritten as a numberYou have to state "a device meeting these conditions"
Sharing among manyTaken for grantedThe driver has to support it

Writing just "1 GPU" gives no way to know which model you will get. Some work cannot run on an 8GB card, and some libraries run only on particular generations.

What DRA Is

DRA (Dynamic Resource Allocation) is the Kubernetes allocation mechanism for handling such complex devices.

Instead of requesting a number, you create a separate request resource and have the pod reference it. The request states "which class of device is needed and which conditions it must satisfy".

The device resource structure

Here is what this gives you.

What you can doDescription
Select by conditionRequest something like "a GPU with 16GB or more of memory"
Share among several podsIf the driver supports it, one device is shared
Share across namespacesDifferent teams use the same device together
Check per-device statusSee on screen which device is allocated where

A driver is required for it to work. DRA is the Kubernetes framework; discovering and allocating actual devices is done by the driver the GPU vendor provides. Without a driver, all the lists are empty.

The Four Resources and Their Roles

ResourceScopeWho creates itRole
DeviceClassClusterDriver or operatorsThe kind of device and the conditions for selecting it
ResourceSliceClusterThe driver, automaticallyThe list of actual devices per node
ResourceClaimNamespaceUsersThe request to use a device
ResourceClaimTemplateNamespaceUsersA mold that generates a request per pod

The first two are read-only. Users create the last two.

Device Classes

These define the kind of device. Go to Devices > Device Classes.

Device class list
ItemDescription
NameThe name used when requesting
SelectorsThe conditions for devices belonging to this class
Default configurationSettings attached automatically when requesting with this class

Classes are registered per GPU model. A pod requests "a device of this kind" by class name and does not specify which device on which node.

Resource Slices

This is the list of devices actually installed on nodes. View them under Devices > Resource Slices.

The driver inspects the nodes and registers them automatically. Users neither create nor edit them.

What to checkDescription
DriverThe driver that published this list
NodeWhich node they are installed on
Device listThat node's devices and each of their attributes

If a requested device is not allocated, check here first whether any devices are left.

How to Read Shareable Devices

A device is shareable among several pods if the following values appear on its detail.

ItemMeaning
ShareableWhether several parties can share this device
CapacityThe total amount available to share. For example, 16311Mi of memory
Request rangeThe range and unit a single request can take

With sharing on, the same device is shared even across namespaces. Team A holding a GPU still leaves the remainder for team B.

With sharing off, one pod occupies the whole device. Other requests then wait until the first holder releases it.

Sharing support depends on the driver version. If sharing seems not to work, ask operations staff for the driver version.

Resource Claims

This is the request to use a device. View them under Devices > Resource Claims.

StatusMeaning
PendingLooking for a device to allocate
AllocatedA device has been allocated

The detail screen shows the following.

ItemWhat it tells you
RequestWhich class of device, how many, and under what conditions
Allocation resultWhich device on which node was allocated
ConsumersWhich pods are using this request
Device stateThe driver, pool, and name of the allocated device, and the sharing identifier

If the consumers are empty while the status is Allocated, the device is being held without being used. If other pods are waiting, it is a candidate for cleanup.

Resource Claim Templates

If several pods repeat the same request, create one under Devices > Resource Claim Templates.

When a Deployment starts three pods, three claims are created automatically from the template. You do not have to create a claim per pod by hand.

SituationWhat to use
One pod uses a particular device for a long timeA resource claim
There are several replicas and each needs a deviceA resource claim template
The request should disappear when the pod doesA template

Claims created from a template share the pod's lifetime. When the pod is deleted, the claim is deleted with it and the device is released. Claims created by hand remain after the pod is gone and have to be cleaned up manually.

The Order for Using a GPU

  1. Check the available device kinds under Device Classes.
  2. Look at the remaining devices and whether they are shareable under Resource Slices.
  3. Put a resource claim (or template) into the pod definition and deploy.
  4. Confirm that the resource claim turns Allocated.
  5. Confirm that the pod turns Running (see 3.1).

Using a GPU From a Pod — YAML

First Choose Between the Two Request Methods

There are two ways to attach a device to a pod, and which one you use decides whether it is shared.

Reference methodResultWhen to use it
resourceClaimName — points at a pre-created claim by nameSeveral pods share the same deviceWhen GPUs are short and several workloads must share
resourceClaimTemplateName — points at a templateA new claim is created per pod, each occupying one deviceWhen each replica needs its own device

Confusing the two makes the symptoms puzzling. Using a template where you meant to share leaves the second pod onward in Pending on a node with one GPU. The first pod is fine, which makes the configuration look correct.

Method 1 — Several Pods Sharing One GPU

First create a claim. It has to exist before the pods.

apiVersion: resource.k8s.io/v1
kind: ResourceClaim
metadata:
name: shared-gpu
namespace: my-app
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com # the name from the device class screen
allocationMode: ExactCount
count: 1
FieldDescription
deviceClassNameWrite the name from the device class screen exactly. A nonexistent name leaves the claim in Pending
allocationModeExactCount takes as many as count; All takes every device matching the conditions
countHow many to request

Then the pod points at it by name. It has to be written in two places: the pod spec and the container spec.

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-gpu-app
namespace: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-gpu-app
template:
metadata:
labels:
app: my-gpu-app
spec:
resourceClaims: # (1) which claims the pod uses
- name: gpu # the name used inside the pod
resourceClaimName: shared-gpu # the actual ResourceClaim name
containers:
- name: app
image: registry.example.com/my-gpu-app:1.0
resources:
claims: # (2) which of those this container uses
- name: gpu # must match the name in (1)
limits:
cpu: "2"
memory: 4Gi
PlaceWhat it does
spec.resourceClaimsThe list of claims the pod will use. These names are local to the pod
containers[].resources.claimsWhich of what the pod received to attach to this container

Writing only one of the two leaves the device unattached. Written only on the pod, the GPU is not visible in the container; written only on the container, pod creation is rejected.

In this example, all three replicas use the same single GPU. The consumers on the resource claim detail show three pods together.

Method 2 — Each Replica Taking Its Own GPU

Create a template and have the pod point at it.

apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: dedicated-gpu
namespace: my-app
spec:
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com
allocationMode: ExactCount
count: 1

spec appearing twice is correct. The outer one is the template's specification, and the inner one is the specification of the claims the template will stamp out.

spec:
resourceClaims:
- name: gpu
resourceClaimTemplateName: dedicated-gpu # the template name
containers:
- name: app
image: registry.example.com/my-gpu-app:1.0
resources:
claims:
- name: gpu

You need as many devices as replicas. Three replicas require three GPUs, and if there are not enough, the remaining pods stay in Pending.

How It Differs From the Old Way

Previously you wrote the GPU count in the container's resource limits.

resources:
limits:
nvidia.com/gpu: "1" # the old way

Remove this line when moving to DRA. Using both requests the device twice. Leave the CPU and memory limits as they are (see 3.1).

The old wayDRA
Where you requestThe container's resource limitsA ResourceClaim
What you can requestA count onlyA count plus conditions (model, memory, whether partitioned)
SharingA node-level setting, so it applies to the whole nodePer claim, so only among the workloads that need it
Where to checkAllocatable resources on the node detailThe Devices menu

What to Check After Applying

OrderWhereIf it is fine
1Devices > Resource ClaimsStatus is Allocated
2The detail on the same screenThe allocation result names a node and device
3The detail on the same screenYour pod is among the consumers
4Workloads > PodsRunning (see 3.1)

If step 1 is Pending, the pod will not start. See "When Nothing Is Allocated" below.

Common Mistakes

SymptomCause
The second pod onward is PendingYou meant to share but used resourceClaimTemplateName
The GPU is not visible in the containercontainers[].resources.claims was omitted
Pod creation is rejectedspec.resourceClaims was omitted, or the name values in the two places differ
The claim stays PendingdeviceClassName differs from the actual device class name
It takes twice as many devicesThe old way (limits.nvidia.com/gpu) was left in place as well
Sharing with pods in another namespace does not workClaims are namespace-scoped. Whether it is possible depends on the driver version, so check with operations staff

You cannot pin a node directly. DRA requires the scheduler to allocate the device, so hard-coding a node name on the pod prevents allocation. To send it to a particular node, use node selection conditions (nodeSelector).

When the Device List Is Empty

If both Device Classes and Resource Slices are empty, there is no driver or it is not working.

CheckDescription
Whether GPU nodes existConfirm GPU nodes in the node list (see 2.1)
Whether the driver pods are upThe driver runs as a pod on every GPU node
Whether the cluster supports DRACheck with operations staff

This screen is read-only. Driver installation and configuration are performed by operations staff.

When Nothing Is Allocated

SymptomCauseWhat to check
The claim is PendingNo devices leftCheck devices in use under Resource Slices
The claim is PendingNo device matches the conditionsWhether the requested class and attributes match the actual devices
The claim is PendingSharing is off and another pod took it firstWhether that device is shareable
The pod is PendingThe claim was allocated but the node lacks resourcesThe CPU and memory headroom on that node
Several teams cannot use it at onceThe driver does not support sharingThe driver version

GPUs are usually fewer than nodes, so contention is high. Check in the resource claim list whether unused pods are holding devices. Cleaning up development and test pods frees space.

The Relationship Between MIG and DRA

The two are easy to confuse, but they are at different layers.

MIGDRA
What it isA feature that splits GPU hardware into several piecesThe Kubernetes device allocation mechanism
Where it livesInside the GPUInside Kubernetes
What it providesDedicated compute and memory per piece, plus fault isolationFinding and allocating a device matching the conditions
Which GPUsOnly some data center modelsEvery GPU the driver supports

"Using DRA means MIG is unnecessary" is not the case. MIG splits the GPU into pieces, and DRA allocates those pieces to pods. The two can be used together.

Hardware-level isolation (one job not affecting the performance or stability of another) is provided only by MIG. DRA's sharing is software-level, so the parties can affect each other.

Which approach is in use depends on the cluster configuration. If partitioned devices appear in the device list under Resource Slices, MIG is applied.