このページでは、Google Kubernetes Engine クラスタに動的リソース割り当て(DRA)ワークロードをデプロイする方法について説明します。このページでは、ResourceClaimTemplate
を作成して DRA でハードウェアをリクエストし、基本的なワークロードをデプロイして、Kubernetes が Pod にハードウェアを柔軟に割り当てる方法を示します。
このページは、AI / ML やハイ パフォーマンス コンピューティング(HPC)などのワークロードを実行するアプリケーション オペレーターとデータ エンジニアを対象としています。
リソースの動的割り当てについて
DRA は Kubernetes の組み込み機能で、クラスタ内のハードウェアを Pod とコンテナ間で柔軟にリクエストして割り当て、共有できます。詳細については、リソースの動的割り当てについてをご覧ください。
DRA によるデバイスのリクエストについて
DRA 用に GKE インフラストラクチャを設定すると、ノードの DRA ドライバがクラスタ内に DeviceClass
オブジェクトを作成します。DeviceClass は、ワークロードにリクエストできるデバイスのカテゴリ(GPU など)を定義します。必要に応じて、プラットフォーム管理者は、特定のワークロードでリクエストできるデバイスを制限する追加の DeviceClass をデプロイできます。
DeviceClass
内のデバイスをリクエストするには、次のいずれかのオブジェクトを作成します。
ResourceClaim
: ResourceClaim を使用すると、Pod またはユーザーは DeviceClass 内の特定のパラメータをフィルタリングして、ハードウェア リソースをリクエストできます。ResourceClaimTemplate
: ResourceClaimTemplate は、Pod ごとの新しい ResourceClaim を自動的に作成するために Pod が使用できるテンプレートを定義します。
ResourceClaim
オブジェクトと ResourceClaimTemplate
オブジェクトの詳細については、ResourceClaims
と ResourceClaimTemplates
を使用する場合をご覧ください。
このページの例では、基本的な ResourceClaimTemplate
を使用して、指定されたデバイス構成をリクエストします。詳細については、ResourceClaimTemplateSpec
Kubernetes のドキュメントをご覧ください。
制限事項
- ノードの自動プロビジョニングはサポートされていません。
- Autopilot クラスタは DRA をサポートしていません。
- 次の GPU 共有機能は使用できません。
- 時間共有 GPU
- マルチインスタンス GPU
- マルチプロセス Service(MPS)
要件
DRA を使用するには、GKE バージョンが 1.32.1-gke.1489001 以降である必要があります。
また、次の要件と制限事項にも注意してください。
始める前に
作業を始める前に、次のタスクを完了済みであることを確認してください。
- Google Kubernetes Engine API を有効にする。 Google Kubernetes Engine API の有効化
- このタスクに Google Cloud CLI を使用する場合は、gcloud CLI をインストールして初期化する。すでに gcloud CLI をインストールしている場合は、
gcloud components update
を実行して最新のバージョンを取得する。
- GKE クラスタが DRA ワークロード用に構成されていることを確認する。
DRA を使用してワークロードをデプロイする
Pod ごとのデバイス割り当てをリクエストするには、まず ResourceClaimTemplate
を作成し、GPU または TPU のリクエストを記述する ResourceClaim
を生成します。これは、Kubernetes がテンプレートとして使用し、ワークロード内の Pod ごとに新しい ResourceClaim
オブジェクトを作成します。ワークロードに ResourceClaimTemplate
を指定すると、Kubernetes はリクエストされたリソースを割り振り、対応するノードに Pod をスケジュールします。
GPU
次のマニフェストを
claim-template.yaml
として保存します。apiVersion: resource.k8s.io/v1beta1 kind: ResourceClaimTemplate metadata: name: gpu-claim-template spec: spec: devices: requests: - name: single-gpu deviceClassName: gpu.nvidia.com allocationMode: ExactCount count: 1
ResourceClaimTemplate
を作成します。kubectl create -f claim-template.yaml
ResourceClaimTemplate
を参照するワークロードを作成するには、次のマニフェストをdra-gpu-example.yaml
として保存します。apiVersion: apps/v1 kind: Deployment metadata: name: dra-gpu-example spec: replicas: 1 selector: matchLabels: app: dra-gpu-example template: metadata: labels: app: dra-gpu-example spec: containers: - name: ctr image: ubuntu:22.04 command: ["bash", "-c"] args: ["while [ 1 ]; do date; echo $(nvidia-smi -L || echo Waiting...); sleep 60; done"] resources: claims: - name: single-gpu resourceClaims: - name: single-gpu resourceClaimTemplateName: gpu-claim-template tolerations: - key: "nvidia.com/gpu" operator: "Exists" effect: "NoSchedule"
ワークロードをデプロイします。
kubectl create -f dra-gpu-example.yaml
TPU
次のマニフェストを
claim-template.yaml
として保存します。apiVersion: resource.k8s.io/v1beta1 kind: ResourceClaimTemplate metadata: name: tpu-claim-template spec: spec: devices: requests: - name: all-tpus deviceClassName: tpu.google.com allocationMode: All
この
ResourceClaimTemplate
は、GKE がすべてのResourceClaim
に TPU ノードプール全体を割り当てることをリクエストします。ResourceClaimTemplate
を作成します。kubectl create -f claim-template.yaml
ResourceClaimTemplate
を参照するワークロードを作成するには、次のマニフェストをdra-tpu-example.yaml
として保存します。apiVersion: apps/v1 kind: Deployment metadata: name: dra-tpu-example spec: replicas: 1 selector: matchLabels: app: dra-tpu-example template: metadata: labels: app: dra-tpu-example spec: containers: - name: ctr image: ubuntu:22.04 command: - /bin/sh - -c - | echo "Environment Variables:" env echo "Sleeping indefinitely..." sleep infinity resources: claims: - name: all-tpus resourceClaims: - name: all-tpus resourceClaimTemplateName: tpu-claim-template tolerations: - key: "google.com/tpu" operator: "Exists" effect: "NoSchedule"
ワークロードをデプロイします。
kubectl create -f dra-tpu-example.yaml
ハードウェアの割り当てを確認する
ワークロードにハードウェアが割り当てられていることを確認するには、ResourceClaim
を確認するか、Pod のログを調べます。
GPU
デプロイしたワークロードに関連付けられている
ResourceClaim
を取得します。kubectl get resourceclaims
出力は次のようになります。
NAME STATE AGE dra-gpu-example-64b75dc6b-x8bd6-single-gpu-jwwdh allocated,reserved 9s
Pod に割り当てられたハードウェアの詳細を取得するには、次のコマンドを実行します。
kubectl describe resourceclaims RESOURCECLAIM
RESOURCECLAIM
は、前の手順の出力から取得したResourceClaim
のフルネームに置き換えます。出力は次のようになります。
Name: dra-gpu-example-64b75dc6b-x8bd6-single-gpu-jwwdh Namespace: default Labels: <none> Annotations: resource.kubernetes.io/pod-claim-name: single-gpu API Version: resource.k8s.io/v1beta1 Kind: ResourceClaim Metadata: Creation Timestamp: 2025-03-31T17:11:37Z Finalizers: resource.kubernetes.io/delete-protection Generate Name: dra-gpu-example-64b75dc6b-x8bd6-single-gpu- Owner References: API Version: v1 Block Owner Deletion: true Controller: true Kind: Pod Name: dra-gpu-example-64b75dc6b-x8bd6 UID: cb3cb1db-e62a-4961-9967-cdc7d599105b Resource Version: 12953269 UID: 3e0c3925-e15a-40e9-b552-d03610fff040 Spec: Devices: Requests: Allocation Mode: ExactCount Count: 1 Device Class Name: gpu.nvidia.com Name: single-gpu Status: Allocation: Devices: Results: Admin Access: <nil> Device: gpu-0 Driver: gpu.nvidia.com Pool: gke-cluster-gpu-pool-11026a2e-zgt1 Request: single-gpu Node Selector: # lines omitted for clarity Reserved For: Name: dra-gpu-example-64b75dc6b-x8bd6 Resource: pods UID: cb3cb1db-e62a-4961-9967-cdc7d599105b Events: <none>
デプロイしたワークロードのログを取得するには、次のコマンドを実行します。
kubectl logs deployment/dra-gpu-example --all-pods=true | grep "GPU"
出力は次のようになります。
[pod/dra-gpu-example-64b75dc6b-x8bd6/ctr] GPU 0: Tesla T4 (UUID: GPU-2087ac7a-f781-8cd7-eb6b-b00943cc13ef)
この出力は、GKE が Pod に 1 つの GPU を割り当てたことを示しています。
TPU
デプロイしたワークロードに関連付けられている
ResourceClaim
を取得します。kubectl get resourceclaims | grep dra-tpu-example
出力は次のようになります。
NAME STATE AGE dra-tpu-example-64b75dc6b-x8bd6-all-tpus-jwwdh allocated,reserved 9s
Pod に割り当てられたハードウェアの詳細を取得するには、次のコマンドを実行します。
kubectl describe resourceclaims RESOURCECLAIM -o yaml
RESOURCECLAIM
は、前の手順の出力から取得したResourceClaim
のフルネームに置き換えます。出力は次のようになります。
apiVersion: resource.k8s.io/v1beta1 kind: ResourceClaim metadata: annotations: resource.kubernetes.io/pod-claim-name: all-tpus creationTimestamp: "2025-03-04T21:00:54Z" finalizers: - resource.kubernetes.io/delete-protection generateName: dra-tpu-example-59b8785697-k9kzd-all-gpus- name: dra-tpu-example-59b8785697-k9kzd-all-gpus-gnr7z namespace: default ownerReferences: - apiVersion: v1 blockOwnerDeletion: true controller: true kind: Pod name: dra-tpu-example-59b8785697-k9kzd uid: c2f4fe66-9a73-4bd3-a574-4c3eea5fda3f resourceVersion: "12189603" uid: 279b5014-340b-4ef6-9dda-9fbf183fbb71 spec: devices: requests: - allocationMode: All deviceClassName: tpu.google.com name: all-tpus status: allocation: devices: results: - adminAccess: null device: "0" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "1" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "2" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "3" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "4" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "5" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "6" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus - adminAccess: null device: "7" driver: tpu.google.com pool: gke-tpu-2ec29193-bcc0 request: all-tpus nodeSelector: nodeSelectorTerms: - matchFields: - key: metadata.name operator: In values: - gke-tpu-2ec29193-bcc0 reservedFor: - name: dra-tpu-example-59b8785697-k9kzd resource: pods uid: c2f4fe66-9a73-4bd3-a574-4c3eea5fda3f
デプロイしたワークロードのログを取得するには、次のコマンドを実行します。
kubectl logs deployment/dra-tpu-example --all-pods=true | grep "TPU"
出力は次のようになります。
[pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_CHIPS_PER_HOST_BOUNDS=2,4,1 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_TOPOLOGY_WRAP=false,false,false [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_SKIP_MDS_QUERY=true [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_RUNTIME_METRICS_PORTS=8431,8432,8433,8434,8435,8436,8437,8438 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_WORKER_ID=0 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_WORKER_HOSTNAMES=localhost [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_TOPOLOGY=2x4 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_ACCELERATOR_TYPE=v6e-8 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_HOST_BOUNDS=1,1,1 [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_TOPOLOGY_ALT=false [pod/dra-tpu-example-59b8785697-tm2lc/ctr] TPU_DEVICE_0_RESOURCE_CLAIM=77e68f15-fa2f-4109-9a14-6c91da1a38d3
この出力は、ノードプール内のすべての TPU が Pod に割り振られたことを示しています。