Add resource claims to pods

You can use resource claims and resource claim templates with Attribute-Based GPU Allocation to allow you to request your workloads to be scheduled on nodes with specific graphics processing units (GPU).

Resource claims can be used with multiple pods, but resource claim templates can be used with only one pod. For more information, see "About GPU allocation objects and concepts".

The example in the following procedure creates a resource claim to schedule a pod on a node with the assign a specific GPU to and a resource claim to share a GPU between container1 and container2.

Prerequisites
  • A Dynamic Resource Allocation (DRA) driver is installed. For more information on DRA, see "Dynamic Resource Allocation" (Kubernetes documentation).

  • A resource slice has been created.

  • If your resource slice is allocating a partitioned device, you enabled the required Technology Preview features for your cluster by adding the TechPreviewNoUpgrade feature set to the FeatureGate CR named cluster. For information about enabling Feature Gates, see "Enabling features using feature gates".

    Warning

    Enabling the TechPreviewNoUpgrade feature set on your cluster cannot be undone and prevents minor version updates. This feature set allows you to enable these Technology Preview features on test clusters, where you can fully test them. Do not enable this feature set on production clusters.

  • A resource claim and/or resource claim template has been created.

    Example resource claim object
    apiVersion: resource.k8s.io/v1
    kind: ResourceClaim
    metadata:
      namespace: gpu-claim
      name: gpu-devices
    spec:
      devices:
        requests:
        - name: req-0
          exactly:
            name: 2g-10gb
            deviceClassName: example-device-class
            selectors:
            - cel:
                expression: "device.attributes['driver.example.com'].profile == '2g.10gb'"
    Example resource claim template object
    apiVersion: resource.k8s.io/v1
    kind: ResourceClaimTemplate
    metadata:
      namespace: gpu-claim
      name: gpu-devices
    spec:
      spec:
        devices:
          requests:
          - name: req-0
            firstAvailable:
            - name: 2g-10gb
              deviceClassName: example-device-class
              selectors:
              - cel:
                  expression: "device.attributes['driver.example.com'].profile == '2g.10gb'"
            - name: 3g-20gb
              deviceClassName: example-device-class
              selectors:
              - cel:
                  expression: "device.attributes['driver.example.com'].profile == '3g.20gb'"
Procedure
  1. Create a pod by creating a YAML file similar to the following:

    Example pod that is requesting resources
    apiVersion: v1
    kind: Pod
    metadata:
      namespace: gpu-allocate
      name: pod1
      labels:
        app: pod
    spec:
      restartPolicy: Never
      containers:
      - name: container0
        image: ubuntu:24.04
        command: ["sleep", "9999"]
        resources:
          claims:
          - name: gpu-claim-template
      - name: container1
        image: ubuntu:24.04
        command: ["sleep", "9999"]
        resources:
          claims:
          - name: gpu-claim
      - name: container2
        image: ubuntu:24.04
        command: ["sleep", "9999"]
        resources:
          claims:
          - name: gpu-claim
      resourceClaims:
      - name: gpu-claim-template
        resourceClaimTemplateName: gpu-devices-template
      - name: gpu-claim
        resourceClaimName: gpu-devices

    where:

    spec.container.resource.claims

    Specifies one or more resource claims to use with this container.

    spec.resourceClaims

    Specifies the resource claims that are required for the containers to start. Include an arbitrary name for the resource claim request and a resource claim, resource claim template, or both.

  2. Create the CRD object:

    $ oc create -f <file_name>.yaml

    For more information on configuring pod resource requests, see "Dynamic Resource Allocation" (Kubernetes documentation).