Skip to content
Use Dynamic Resource Allocation for GPUs

Use Dynamic Resource Allocation for GPUs

SKS nodes can expose their GPUs with the NVIDIA DRA driver for GPUs instead of the NVIDIA device plugin. With Dynamic Resource Allocation (DRA), the driver publishes the GPUs, or their MIG instances, in ResourceSlices, and workloads request them with ResourceClaims or ResourceClaimTemplates that reference one of these DeviceClasses:

With DRA, nodes no longer advertise the nvidia.com/gpu resource, and a pod only gets the GPUs allocated to its claims.

Prerequisites

  • An SKS cluster running Kubernetes 1.34 or greater (resource.k8s.io/v1 API).
  • A GPU instance type for the nodepool.

Install the DeviceClasses

SKS does not install the DeviceClasses. Apply them once per cluster:

cat <<EOF | kubectl apply -f -
apiVersion: resource.k8s.io/v1
kind: DeviceClass
metadata:
  name: gpu.nvidia.com
spec:
  selectors:
  - cel:
      expression: "device.driver == 'gpu.nvidia.com' && device.attributes['gpu.nvidia.com'].type == 'gpu'"
---
apiVersion: resource.k8s.io/v1
kind: DeviceClass
metadata:
  name: mig.nvidia.com
spec:
  selectors:
  - cel:
      expression: "device.driver == 'gpu.nvidia.com' && device.attributes['gpu.nvidia.com'].type == 'mig'"
EOF

Enable DRA on SKS Standard NodePools

Warning

Enabling or disabling the DRA driver on an existing nodepool only affects newly provisioned nodes. To make current nodes pick up the change, you have to cycle your nodes.

CLI

Create a cluster with a default nodepool using the DRA driver:

exo compute sks create my-cluster \
  --zone ch-gva-2 \
  --nodepool-name gpu-pool \
  --nodepool-size 1 \
  --nodepool-instance-type gpua30.large \
  --nodepool-nvidia-dra-driver

Add a nodepool using the DRA driver to an existing cluster:

exo compute sks nodepool add my-cluster gpu-pool \
  --instance-type gpua30.large \
  --size 1 \
  --nvidia-dra-driver

Enable the DRA driver on an existing nodepool, or pass --nvidia-dra-driver=false to switch back to the device plugin:

exo compute sks nodepool update my-cluster gpu-pool --nvidia-dra-driver

To expose MIG instances, also set a MIG profile with --nvidia-mig-profile (or --nodepool-nvidia-mig-profile): each MIG instance is then published as a mig.nvidia.com device.

Terraform Provider

Set the nvidia_dra_driver attribute of the exoscale_sks_nodepool resource, optionally with nvidia_mig_profile:

resource "exoscale_sks_nodepool" "gpu" {
  zone       = "ch-gva-2"
  cluster_id = exoscale_sks_cluster.my_cluster.id
  name       = "gpu-pool"

  instance_type      = "gpua30.large"
  size               = 1
  nvidia_dra_driver  = true
  nvidia_mig_profile = "1g.6gb" # optional
}

Enable DRA on Karpenter Nodepools

In spec.userData of the Karpenter ExoscaleNodeClass, disable the NVIDIA device plugin and enable the NVIDIA DRA driver. If the device plugin stays enabled, it is used instead of the DRA driver. To expose MIG instances, add the MIG settings described in Use GPU MIG Partitioning.

apiVersion: karpenter.exoscale.com/v1
kind: ExoscaleNodeClass
metadata:
  name: nvidia-dra
spec:
  imageTemplateSelector:
    variant: nvidia
  diskSize: 100                                # Beware that GPU nodes enforce minimum disk size

  securityGroupSelectorTerms:
  - id: "5ea00f6e-1e92-456b-9381-2cb2c5937240" # Don't forget to attach proper security group

  userData: |
    [settings.kubelet-device-plugins.nvidia]
    enabled = false

    [settings.kubelet-dra-drivers.nvidia]
    enabled = true

Important

Karpenter does not yet provision nodes for pods with ResourceClaims, see Limitations.

Running and Testing GPU Jobs

Once nodes are ready, check that their GPUs are published:

kubectl get resourceslices

Create a ResourceClaimTemplate requesting one full GPU, and a pod using it. On nodepools with a MIG profile, use the mig.nvidia.com DeviceClass instead.

cat <<EOF | kubectl apply -f -
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
  name: single-gpu
spec:
  spec:
    devices:
      requests:
      - name: gpu
        exactly:
          deviceClassName: gpu.nvidia.com
---
apiVersion: v1
kind: Pod
metadata:
  name: gpu-pod
spec:
  restartPolicy: Never
  resourceClaims:
  - name: gpu
    resourceClaimTemplateName: single-gpu
  containers:
    - name: cuda-container
      image: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda11.7.1-ubuntu20.04
      resources:
        claims:
        - name: gpu
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
EOF

Check that the claim is allocated and that the pod ran on the GPU:

kubectl get resourceclaims
kubectl logs gpu-pod

Limitations

Karpenter does not yet provision nodes for pods with ResourceClaims: such pods stay pending until a node with a matching device exists, for example in an SKS Standard nodepool.

Last updated on