Dynamic resource allocation is a Kubernetes API that lets you request and share resources, like GPUs, across Pods and containers in your Google Distributed Cloud bare metal clusters. Third-party drivers manage these devices, and Kubernetes allocates them dynamically, much like storage volumes. Your AI workloads don't need to target specific nodes or request the exact number of attached devices. This document shows you how to configure your GPU workloads to use dynamic resource allocation.
Before you begin
Before you configure your GPU workloads to use dynamic resource allocation, verify that the following prerequisites are met:
- Your bare metal cluster is at version 1.33.0 or later.
- Your operating system is either Ubuntu 22.04 or Red Hat Enterprise Linux (RHEL) 9.4.
- You have updated your cluster to enable dynamic resource allocation as described in Enable dynamic resource allocation.
- You have at least one node machine with a GPU attached and the NVIDIA GPU driver installed. For more information, see Install or uninstall the bundled NVIDIA GPU Operator.
- If you are using the bundled NVIDIA GPU operator, version 1.33.0 or later enables Container Device Interface (CDI) by default.
If you are using a manually installed GPU operator, ensure CDI is enabled
in the
ClusterPolicy. - You have followed the instructions in NVIDIA DRA Driver for GPUs to install the NVIDIA DRA driver on all GPU-attached nodes.
Create GPU workloads that use dynamic resource allocation
For your GPU workloads to take advantage of dynamic resource allocation to request GPUs, they must
be in a shared namespace with a ResourceClaim that describes the request for
GPU device allocation. Your workloads must reference the ResourceClaim for
Kubernetes to assign GPU resources.
The following steps set up an environment in which your workloads use dynamic resource allocation to request GPU resources:
To create resources related to dynamic resource allocation, create a new
Namespacein your cluster:cat <<EOF | kubectl apply --kubeconfig=CLUSTER_KUBECONFIG -f - apiVersion: v1 kind: Namespace metadata: name: NAMESPACE_NAME EOFReplace the following:
CLUSTER_KUBECONFIG: the path of the user cluster kubeconfig file.NAMESPACE_NAMEwith the name for your dynamic resource allocation namespace.
Create a
ResourceClaimto describe the request for GPU access:cat <<EOF | kubectl apply --kubeconfig=CLUSTER_KUBECONFIG -f - apiVersion: resource.k8s.io/v1beta1 kind: ResourceClaim metadata: namespace: NAMESPACE_NAME name: RESOURCE_CLAIM_NAME spec: devices: requests: - name: gpu deviceClassName: gpu.nvidia.com EOFReplace
RESOURCE_CLAIM_NAMEwith the name of your resource claim for GPU requests.Create workloads that reference the
ResourceClaimcreated in the preceding step.The following workload examples show how to reference a
ResourceClaimnamedgpu-claimin thedra-testnamespace. The containers in thepod1Pod are NVIDIA compute unified device architecture (CUDA) samples designed to run CUDA workloads on the GPUs. When thepod1Pod completes successfully, it indicates that the dynamic resource allocation capability is working properly and dynamic resource allocation is ready to manage GPU resources in your cluster.Ubuntu
Use the following command to apply the manifest to your cluster:
cat <<EOF | kubectl apply --kubeconfig=CLUSTER_KUBECONFIG -f - apiVersion: v1 kind: Pod metadata: name: pod1 namespace: dra-test spec: restartPolicy: OnFailure resourceClaims: - name: gpu resourceClaimName: gpu-claim containers: - name: ctr0 image: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0 resources: claims: - name: gpu - name: ctr1 image: nvcr.io/nvidia/k8s/cuda-sample:devicequery resources: claims: - name: gpu EOF
RHEL
Use the following command to apply the manifest to your cluster:
cat <<EOF | kubectl apply --kubeconfig=CLUSTER_KUBECONFIG -f - apiVersion: v1 kind: Pod metadata: name: pod1 namespace: dra-test spec: restartPolicy: OnFailure resourceClaims: - name: gpu resourceClaimName: gpu-claim containers: - name: ctr0 image: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0 resources: claims: - name: gpu - name: ctr1 image: nvcr.io/nvidia/k8s/cuda-sample:devicequery resources: claims: - name: gpu EOF
Limitations
Consider the following limitations when you use dynamic resource allocation:
When you use RHEL OS with a supported version of the NVIDIA GPU operator, the Container Device Interface (CDI) handles device injection and SELinux labeling automatically. You aren't required to use manual SELinux policy configuration or set pod
securityContext.This feature uses the
resource.k8s.io/v1beta1API group, which differs from the open source Kubernetes API group for this feature,resource.k8s.io/v1. Thev1open source API group provides more features and better stability than thev1beta1API group.
What's next
- Refer to the Kubernetes documentation for more information about dynamic resource allocation.
- Learn how to serve third-party LLMs on bare metal.