DRA บน NKP 2.19: คู่มืออ้างอิงฉบับเต็มเรื่อง GPU Claim บน Kubernetes 1.36¶
หน้า AI conformance ของ NKP 2.19 พิสูจน์เรื่อง DRA ไว้แค่ว่า API พร้อมใช้ NVIDIA driver รันอยู่ และเห็น A40 ใน ResourceSlice1 แต่ไม่มีตรงไหนที่ schedule pod ผ่าน ResourceClaim จริงเลย โพสต์นี้เลยมาต่อจากจุดที่เช็กนั้นจบ มีครบทั้งคำสั่ง manifest และหลุมที่ต้องระวัง ถ้าจะรัน GPU workload ผ่าน DRA บน NKP 2.19 ให้ได้จริง
Conformance check บอกอะไร และไม่ได้บอกอะไร¶
NKP 2.19 ผ่าน CNCF Kubernetes AI Conformant ของ v1.36 แล้ว ข้างในเป็น Kubernetes v1.36.2, NVIDIA GPU Operator v26.3.3 และ NVIDIA DRA driver chart dra-driver-nvidia-gpu@0.4.1 ทุกตัว deploy เป็น Flux HelmRelease อยู่ใน namespace kommander1
| หน้า conformance พิสูจน์ไว้ | ไม่ได้แสดง (มีด้านล่าง) |
|---|---|
resource.k8s.io/v1 มีครบ 4 kind | Pod ที่ได้ GPU ผ่าน claim จริง ๆ |
| มี NVIDIA DeviceClass 5 ตัว | DeviceClass ตัวไหนใช้ได้เลย ตัวไหนต้องเปิด feature gate |
ResourceSlice publish gpu-0 (A40, driver 580.126.18) | เลือก device ตาม attribute ด้วย CEL |
| Pod ของ controller, kubelet plugin และ webhook ขึ้น Running | GPU sharing, MIG, fallback, quota, admin access |
เปิด device plugin ไว้ด้วย เห็น GPU ตัวเดียวกันเป็น nvidia.com/gpu | ทำไมเปิดทั้งคู่บน node เดียวกันถึงเป็นกับดัก |
แถวสุดท้ายสำคัญที่สุด เช็กพื้นฐานเสร็จแล้วให้เริ่มจากเรื่องนี้ก่อนเลย
DRA มีแค่ 4 object¶
ใครเคยใช้ PersistentVolume มาแล้ว เข้าใจ DRA ได้ทันที ResourceClaim ก็คือ PVC ของ device นั่นเอง
| Object | Scope | ใครสร้าง | เทียบกับ PV/PVC |
|---|---|---|---|
ResourceSlice | Cluster | kubelet plugin ของ driver | รายการ PV ที่มีอยู่ |
DeviceClass | Cluster | Driver chart หรือ admin | StorageClass |
ResourceClaim | Namespace | เราเอง | PVC ที่สร้างเองกับมือ (แชร์ได้) |
ResourceClaimTemplate | Namespace | เราเอง | volumeClaimTemplates (pod ละหนึ่ง claim) |
ลำดับคือ driver publish device ลงใน ResourceSlice → เราขอ DeviceClass ผ่าน claim → scheduler เลือกทั้ง node และ device ตัวที่จะได้ → kubelet plugin เตรียม device แล้ว inject เข้า container ผ่าน CDI
ขั้นสุดท้ายนี่แหละที่ทำให้ pod ที่ใช้ DRA ไม่ต้องใส่ runtimeClassName: nvidia เพราะ containerd 2.x เปิด CDI ไว้เป็น default อยู่แล้ว และ GPU node ของ NKP ก็รัน containerd 2.3.11
Kubernetes 1.36 มีอะไรให้ใช้¶
DRA core เป็น GA ตั้งแต่ Kubernetes 1.34 และ 1.35 lock feature gate ให้เปิดถาวร23 พอมา 1.36 ฟีเจอร์ส่วนใหญ่ที่ได้ใช้จริงก็ขยับ stage ขึ้นมาแล้ว4
| Feature | Gate | Stage ใน 1.36 | เปิดเป็น default ไหม |
|---|---|---|---|
| Core DRA (claim, class, slice) | DynamicResourceAllocation | Stable | Lock เปิดไว้ |
Prioritized list (firstAvailable) | DRAPrioritizedList | Stable | เปิด |
| Admin access | DRAAdminAccess | Stable | เปิด |
| Extended resource mapping (KEP-5004) | DRAExtendedResource | Beta | เปิด |
| Device taint และ toleration | DRADeviceTaints | Beta | เปิด |
Object DeviceTaintRule | DRADeviceTaintRules | Beta | ปิด |
| Partitionable device | DRAPartitionableDevices | Beta | เปิด |
| Consumable capacity | DRAConsumableCapacity | Beta | เปิด |
| Device binding condition | DRADeviceBindingConditions | Beta | เปิด |
| Device status ใน claim | DRAResourceClaimDeviceStatus | Beta | เปิด |
| Resource pool status, node allocatable, workload claim | หลายตัว | Alpha | ปิด |
ที่มา: Kubernetes feature-gate reference2
ข้อจำกัดหนึ่งที่ยังเหมือนเดิม คือ scheduler preempt pod เพื่อเอา DRA resource มาไม่ได้ Pod ที่ priority สูงแต่รอ GPU ที่มีคน claim อยู่ จะค้าง Pending จนกว่าเจ้าของเดิมจะจบงาน5 ใครที่ทุกวันนี้ใช้ priority-based preemption แบ่ง GPU ให้ยุติธรรม ต้องคิดเรื่องนี้ให้จบก่อน migrate
NVIDIA DRA driver 0.4.1 มีอะไรให้ใช้¶
Driver ตัวนี้ย้ายมาอยู่ที่ kubernetes-sigs/dra-driver-nvidia-gpu และเริ่มใช้ semver ตั้งแต่ v0.4.013 แบ่งเป็นสองส่วน คือ GPU กับ ComputeDomain (Multi-Node NVLink) README ของโปรเจกต์เขียนไว้ว่า ComputeDomain "officially supported" แล้ว ส่วนฟีเจอร์ GPU allocation ยังเป็นแค่ "can be tried out" และ "are not yet officially supported"8
DeviceClass ทั้ง 5 ตัวบน conformance cluster เลือก device แบบนี้:9
| DeviceClass | เลือกอะไร | ใช้กับ A40 ของ NKP ได้เลยไหม |
|---|---|---|
gpu.nvidia.com | GPU ทั้งใบ (type == 'gpu') map เป็น nvidia.com/gpu | ได้ |
mig.nvidia.com | MIG instance ที่แบ่งไว้ก่อนแล้ว (type == 'mig') | ไม่ได้ — A40 ทำ MIG ไม่ได้ |
vfio.gpu.nvidia.com | GPU ที่ bind กับ vfio-pci ไว้ให้ VM | ต้องเปิด gate PassthroughSupport |
compute-domain-daemon.nvidia.com | IMEX daemon ของ ComputeDomain | ใช้ได้แค่ hardware NVLink ระดับ GB200 |
compute-domain-default-channel.nvidia.com | IMEX channel ให้ pod ใน ComputeDomain | ใช้ได้แค่ hardware NVLink ระดับ GB200 |
ดู node label nvidia.com/mig.capable=false บน conformance cluster ก็ยืนยันแถว MIG ได้1
ฟีเจอร์หลายอย่างที่น่าจะอยากใช้ ยังต้องเปิด feature gate ของ driver ก่อน ซึ่งเป็นคนละชุดกับ gate ของ Kubernetes ใน 0.4.1 มีดังนี้:10
| Driver feature gate | เปิดให้ทำอะไรได้ | Stage | Default |
|---|---|---|---|
TimeSlicingSettings | กำหนด time-slice interval เองใน GpuConfig | Alpha | ปิด |
MPSSupport | sharing.strategy: MPS | Alpha | ปิด |
PassthroughSupport | allocate ผ่าน vfio.gpu.nvidia.com | Alpha | ปิด |
DynamicMIG | สร้าง MIG instance ตอนขอ | Alpha | ปิด |
NVMLDeviceHealthCheck | ใช้ NVML mark GPU ที่ไม่ healthy | Alpha | ปิด |
DeviceMetadata | ไฟล์ device metadata ใน container | Alpha | ปิด |
IMEXDaemonsWithDNSNames | DNS name ให้ IMEX daemon | Beta | เปิด |
ComputeDomainCliques | ComputeDomainClique CRD | Beta | เปิด |
ถ้าแค่ allocate GPU ทั้งใบ หรือให้หลาย container แชร์ claim เดียวกัน ไม่ต้องเปิด gate อะไรเลย นอกนั้นในตารางนี้ต้องเปิดทั้งหมด
Step 1: Verify DRA บน NKP cluster¶
รันคำสั่งชุดนี้กับ cluster ที่มี GPU node หน้า conformance ใช้ workspace namespace kommander1
- DRA API ตอบที่ v1
- HelmRelease ของ DRA driver ขึ้น Ready
- มี DeviceClass ครบ
- GPU node ทุกตัวมี ResourceSlice
- Pod ของ controller และ kubelet plugin ขึ้น Running
kubectl api-resources --api-group=resource.k8s.io
kubectl get helmrelease nvidia-dra-driver -n kommander
kubectl get deviceclasses
kubectl get resourceslices -o wide
kubectl get pods -n kommander | grep dra-driver
ผลที่ควรได้ (จาก conformance cluster):
NAME SHORTNAMES APIVERSION NAMESPACED KIND
deviceclasses resource.k8s.io/v1 false DeviceClass
resourceclaims resource.k8s.io/v1 true ResourceClaim
resourceclaimtemplates resource.k8s.io/v1 true ResourceClaimTemplate
resourceslices resource.k8s.io/v1 false ResourceSlice
dra-driver-nvidia-gpu-controller-5766489b58-llkm2 1/1 Running
dra-driver-nvidia-gpu-kubelet-plugin-skjzq 2/2 Running
dra-driver-nvidia-gpu-webhook-6bfb76d88d-2sgwt 1/1 Running
จากนั้น dump GPU ทุกตัวที่ driver เห็นออกมา บรรทัดละ device ต่อไปนี้ให้ดู GPU inventory จากตรงนี้ ไม่ใช่จาก node label:
kubectl get resourceslices -o json | jq -r '
.items[] | select(.spec.driver == "gpu.nvidia.com")
| .spec.nodeName as $node
| .spec.devices[]
| [$node, .name,
.attributes.type.string,
.attributes.productName.string,
.attributes.driverVersion.version,
.capacity.memory.value] | @tsv'
ค่า memory ตรงนี้ใส่ไว้เป็นตัวอย่าง ส่วน field อื่นตรงกับที่หน้า conformance แสดง1
Attribute ที่ใช้เลือก device ได้¶
kubelet plugin 0.4.1 publish attribute ชุดนี้ให้ GPU ทั้งใบทุกตัว:11
| Attribute | CEL type | ค่าบน A40 |
|---|---|---|
type | string | gpu |
uuid | string | GPU-0384e187-... |
productName | string | NVIDIA A40 |
brand | string | เช่น Nvidia |
architecture | string | Ampere |
cudaComputeCapability | version | 8.6.0 |
driverVersion | version | 580.126.18 |
cudaDriverVersion | version | เช่น 13.0.0 |
resource.kubernetes.io/pcieRoot | string | PCIe root complex (ถ้ามีข้อมูล) |
Capacity มี memory (หน่วย bytes) ส่วน MIG device จะมี multiprocessors กับ profile เพิ่มมา
Step 2: หนึ่ง node ใช้ allocation path เดียว¶
เรื่องนี้หน้า conformance ไม่ได้พูดตรง ๆ ปกติ DRA driver chart จะไม่ยอมติดตั้งส่วน GPU ให้ เพราะรันข้าง device plugin แล้วไม่ปลอดภัย:
ถ้าตั้ง 'resources.gpus.enabled=true' จะ deploy DRA driver ตัวนี้คู่กับ GPU device plugin ตัวมาตรฐานบน node เดียวกันไม่ได้ สอง component นี้อาจชนกัน เราจึงยังไม่ให้ default นี้มีผล จนกว่า KEP 5004 จะเป็น GA ใน upstream Kubernetes9
ข้ามด่านนี้ได้ด้วย gpuResourcesEnabledOverride=true ซึ่ง conformance cluster ก็เปิดทั้งคู่ไว้บน A40 node ตัวเดียว ใช้ทำ demo ผ่าน conformance ได้ แต่ ห้ามเอาไปใช้ใน production
ปัญหาที่เกิดคือ device plugin ส่ง GPU-0384... ให้ pod A ผ่าน kubelet ไปแล้ว แต่ scheduler รู้จักแค่ allocation ของ DRA เลยส่ง GPU ตัวเดียวกันให้ claim ของ pod B อีก ได้สอง workload บน GPU ใบเดียว ไม่มี isolation แล้วก็ OOM แบบที่ไม่มีใครอธิบายได้
ใน NKP 2.19 ค่า default ของ GPU Operator chart คือ devicePlugin.enabled: false1 แปลว่าติดตั้งมาเฉย ๆ NKP ใช้ DRA เป็น GPU path หลักอยู่แล้ว ทีม conformance เปิด device plugin แค่เพื่อรันเช็กของ nvidia.com/gpu เท่านั้น
เลือกเป็นราย node pool:
| สถานการณ์ | Device plugin | DRA GPU plugin |
|---|---|---|
| NKP 2.19 cluster ใหม่ | ปิด (default ของ NKP) | เปิด |
Workload เดิมใช้ nvidia.com/gpu | ปิด — ให้ extended resource mapping รับแทน (Step 7) | เปิด |
Operator ของ third-party อ่าน nvidia.com/gpu allocatable จาก node status | เปิด แยก pool ให้ | ปิดบน pool นั้น |
| ช่วง migrate | เปิดบน pool A | เปิดบน pool B |
ถ้าจะแยก pool ให้ติด label ที่ node แล้วกันไม่ให้ plugin แต่ละตัวไปขึ้นบน pool ของอีกตัว GPU Operator อ่าน deploy label ราย node ได้:15
# Pool B: DRA only — stop the device plugin on these nodes
kubectl label node <gpu-node> nvidia.com/gpu.deploy.device-plugin=false --overwrite
kubectl label node <gpu-node> nvidia.com/dra-kubelet-plugin=true
แล้ว pin DRA kubelet plugin ไว้กับ label นั้นผ่าน values override:
แก้ values ของ DRA driver บน NKP¶
อย่าใช้ kubectl edit กับ HelmRelease เพราะ NKP ดูแลผ่าน Kommander แก้ไปเดี๋ยวก็โดน reconcile กลับ หน้า conformance ใช้วิธีของ NKP แทน คือสร้าง values ConfigMap แบบ optional ที่ HelmRelease อ้างไว้อยู่แล้ว1
หาจุดที่ HelmRelease อ้างไว้ก่อน:
หา entry ที่มี "optional": true แล้วสร้าง ConfigMap ตามชื่อนั้นใส่ values ที่ต้องการ ชื่อกับ key ข้างล่างเป็นแค่ placeholder ให้ใช้ค่าจาก output ข้างบน:
apiVersion: v1
kind: ConfigMap
metadata:
name: <name-from-valuesFrom>
namespace: kommander
data:
<key-from-valuesFrom>: |
featureGates:
TimeSlicingSettings: true
MPSSupport: true
kubeletPlugin:
nodeSelector:
nvidia.com/dra-kubelet-plugin: "true"
kubectl apply -f dra-overrides.yaml
flux reconcile helmrelease nvidia-dra-driver -n kommander --with-source
kubectl get helmrelease nvidia-dra-driver -n kommander
สวิตช์เปิดปิด device plugin ของ GPU Operator ก็ใช้วิธีเดียวกัน หน้า conformance สร้าง ConfigMap nvidia-gpu-operator-config-deviceplugin-defaults ที่มี devicePlugin.enabled: true ถ้าอยากกลับไปใช้ DRA อย่างเดียวตาม default ก็ลบ ConfigMap นี้ทิ้ง1
Step 3: Claim แรก — GPU ทั้งใบหนึ่งใบ¶
ถ้า pod แต่ละตัวต้องมี GPU เป็นของตัวเอง ให้ใช้ ResourceClaimTemplate ซึ่ง workload ส่วนใหญ่ก็เป็นแบบนี้
apiVersion: v1
kind: Namespace
metadata:
name: dra-demo
---
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: single-gpu
namespace: dra-demo
spec:
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com
---
apiVersion: v1
kind: Pod
metadata:
name: cuda-smoke
namespace: dra-demo
spec:
restartPolicy: Never
resourceClaims:
- name: gpu
resourceClaimTemplateName: single-gpu
containers:
- name: cuda
image: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0-ubuntu22.04
resources:
claims:
- name: gpu
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoSchedule
ดู wrapper exactly: ให้ดี ใน resource.k8s.io/v1 ต้องมีเสมอ manifest จากบล็อกช่วงปี 2024–2025 ที่วาง deviceClassName ไว้ใต้ request ตรง ๆ เขียนไว้สำหรับ v1beta1 เอาไปใช้บน NKP 2.19 จะ validate ไม่ผ่าน
ถ้า GPU node ไม่ได้ติด taint ก็ลบ toleration ออกได้ จากนั้นรันแล้วดูว่าได้อะไรมา:
kubectl apply -f cuda-smoke.yaml
kubectl logs -n dra-demo cuda-smoke
kubectl get resourceclaims -n dra-demo
kubectl get resourceclaim -n dra-demo -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.allocation.devices.results[*].device}{"\t"}{.status.allocation.devices.results[*].pool}{"\n"}{end}'
[Vector addition of 50000 elements]
...
Test PASSED
NAME STATE AGE
cuda-smoke-gpu-x7k2p allocated,reserved 12s
cuda-smoke-gpu-x7k2p gpu-0 rocky-98-...-gpu-6nz8n-bgqqg-25m89
อยากรู้ว่า pod ถือ GPU ใบไหนอยู่จริง ให้ดูที่ .status.allocation pool คือชื่อ node ส่วน device คือ entry ใน ResourceSlice
Claim ที่ generate จาก template จะหายไปพร้อม pod แต่ ResourceClaim ที่สร้างแยกเองไม่หาย ต้องลบเองถึงจะหาย
ใช้ใน Deployment¶
ใช้ pattern เดิม แค่ย้ายไปไว้ใน pod template replica แต่ละตัวจะได้ claim และ GPU เป็นของตัวเอง:
apiVersion: apps/v1
kind: Deployment
metadata:
name: vllm
namespace: dra-demo
spec:
replicas: 2
selector:
matchLabels: {app: vllm}
template:
metadata:
labels: {app: vllm}
spec:
resourceClaims:
- name: gpu
resourceClaimTemplateName: single-gpu
containers:
- name: vllm
image: vllm/vllm-openai:latest # pin a release tag in production
args: ["--model", "Qwen/Qwen2.5-1.5B-Instruct"]
resources:
claims:
- name: gpu
ถ้าทั้ง cluster มี GPU ใบเดียว replica ที่ 2 จะค้าง Pending และจะเจอ event เดียวกับที่หน้า conformance เจอตอน pod ตัวที่สอง คือ cannot allocate all claims1
Step 4: เลือก device ด้วย CEL¶
ตรงนี้แหละที่ DRA เหนือกว่า nvidia.com/gpu: 1 เราบอกได้เลยว่าต้องการ GPU แบบไหน ไม่ต้องไปพึ่ง node label แล้วหวังว่าจะติดไว้ถูก
ต้องการ GPU memory อย่างน้อย 40 GiB:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com
selectors:
- cel:
expression: >-
device.capacity['gpu.nvidia.com'].memory.compareTo(quantity('40Gi')) >= 0
ต้องเป็น Ampere ขึ้นไป และ driver 580 ขึ้นไป:
selectors:
- cel:
expression: >-
device.attributes['gpu.nvidia.com'].cudaComputeCapability.compareTo(semver('8.0.0')) >= 0 &&
device.attributes['gpu.nvidia.com'].driverVersion.compareTo(semver('580.0.0')) >= 0
ล็อกรุ่น GPU:
ใส่หลาย selector จะเป็นเงื่อนไข AND กัน scheduler เอา selector ไปเทียบกับ ResourceSlice ถ้า selector ไม่ match device ไหนเลย pod จะค้าง Pending เฉย ๆ ไม่ fail ให้เห็น เลยควรเอา expression ไปเทียบกับ inventory จาก jq ใน Step 1 ก่อน
ฝัง policy ไว้ใน DeviceClass ของเราเอง¶
ไม่ต้องให้ทุกทีมมาเขียน CEL ชุดเดิมซ้ำ ๆ สร้าง class ไว้ทีเดียวพอ:
apiVersion: resource.k8s.io/v1
kind: DeviceClass
metadata:
name: inference-40g.nkp.local
spec:
selectors:
- cel:
expression: "device.driver == 'gpu.nvidia.com' && device.attributes['gpu.nvidia.com'].type == 'gpu'"
- cel:
expression: "device.capacity['gpu.nvidia.com'].memory.compareTo(quantity('40Gi')) >= 0"
จากนี้แต่ละทีมแค่ขอ deviceClassName: inference-40g.nkp.local ถ้า hardware policy เปลี่ยน ก็แก้ที่เดียวจบ
Step 5: Fallback ไป GPU รุ่นอื่นด้วย prioritized list¶
Prioritized list เป็น stable แล้วใน 1.364 ใช้ firstAvailable แทน exactly แล้ว scheduler จะไล่ลอง subrequest ทีละตัวตามลำดับ:
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: best-available-gpu
namespace: dra-demo
spec:
spec:
devices:
requests:
- name: gpu
firstAvailable:
- name: large
deviceClassName: gpu.nvidia.com
selectors:
- cel:
expression: "device.capacity['gpu.nvidia.com'].memory.compareTo(quantity('80Gi')) >= 0"
- name: a40
deviceClassName: gpu.nvidia.com
selectors:
- cel:
expression: "device.attributes['gpu.nvidia.com'].productName == 'NVIDIA A40'"
ฝั่ง container ยังอ้าง claim ด้วยชื่อ gpu เหมือนเดิม ถ้าอยากรู้ว่าได้ตัวเลือกไหนไป:
kubectl get resourceclaim <claim> -n dra-demo \
-o jsonpath='{.status.allocation.devices.results[*].request}'
# gpu/a40
App ควรเช็กเองว่าได้ GPU แบบไหนมา (nvidia-smi --query-gpu=memory.total --format=csv) แล้วปรับ batch size หรือ context length ให้พอดี
Step 6: แชร์ GPU¶
กับ driver 0.4.1 แชร์ GPU ผ่าน DRA ได้ 4 แบบ:
| วิธี | ทำยังไง | ต้องเปิด gate ไหม | Isolation |
|---|---|---|---|
| Shared claim ใช้ time-slicing แบบ default | หลาย container หรือหลาย pod อ้าง claim เดียวกัน | ไม่ต้อง | ไม่มี — ใช้ memory ร่วมกัน พังก็พังด้วยกัน |
| Time-slicing แบบกำหนด interval เอง | GpuConfig ตั้ง strategy: TimeSlicing + interval | TimeSlicingSettings | ไม่มี |
| MPS | GpuConfig ตั้ง strategy: MPS | MPSSupport | จำกัด thread % และ pinned memory ราย client |
| MIG | mig.nvidia.com | ไม่ต้อง (static MIG) | ระดับ hardware |
แชร์ระหว่าง container ใน pod เดียว (ไม่ต้องเปิด gate)¶
Container สองตัวที่อ้าง claim เดียวกันจะได้ GPU ใบเดียวกัน:
spec:
resourceClaims:
- name: shared-gpu
resourceClaimTemplateName: single-gpu
containers:
- name: model
image: ubuntu:22.04
command: ["bash", "-c", "nvidia-smi -L; sleep 9999"]
resources:
claims:
- name: shared-gpu
- name: sidecar
image: ubuntu:22.04
command: ["bash", "-c", "nvidia-smi -L; sleep 9999"]
resources:
claims:
- name: shared-gpu
ทั้งสองตัวจะ print UUID ออกมาเหมือนกัน ตัวอย่างนี้คือ gpu-test2 จาก upstream12
แชร์ระหว่าง pod (ไม่ต้องเปิด gate)¶
สร้าง ResourceClaim แยกไว้ตัวหนึ่ง แล้วให้หลาย pod ชี้มาที่ claim นี้ผ่าน resourceClaimName:
apiVersion: resource.k8s.io/v1
kind: ResourceClaim
metadata:
name: team-shared-gpu
namespace: dra-demo
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com
---
# in each pod spec
resourceClaims:
- name: gpu
resourceClaimName: team-shared-gpu
ทุก pod จะไปกองอยู่บน node ที่มี GPU ใบที่ claim ไว้ สำหรับ dev notebook ข้อนี้คือข้อดี แต่ถ้าเป็น Deployment ที่ตั้งใจให้กระจายหลาย node ข้อนี้คือกับดัก
MPS แบบจำกัด resource (ต้องเปิด MPSSupport)¶
ในบรรดาการแชร์แบบ software มีแค่ MPS ที่จำกัด resource ของแต่ละ client ได้ เปิด gate ตาม Step 2 ก่อน แล้วใช้:
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: mps-gpu
namespace: dra-demo
spec:
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: gpu.nvidia.com
config:
- requests: ["gpu"]
opaque:
driver: gpu.nvidia.com
parameters:
apiVersion: resource.nvidia.com/v1beta1
kind: GpuConfig
sharing:
strategy: MPS
mpsConfig:
defaultActiveThreadPercentage: 50
defaultPinnedDeviceMemoryLimit: 10Gi
Container ทุกตัวใน pod ที่แชร์ claim นี้จะได้ SM ตัวละ 50% และ pinned device memory ตัวละ 10 GiB ถ้าอยากใช้ time-slicing แทน ให้เปลี่ยน block sharing เป็น strategy: TimeSlicing กับ timeSlicingConfig: {interval: Long}12
บน conformance cluster มี webhook คอย validate GpuConfig แบบ opaque นี้ตั้งแต่ตอน admission ถ้าไม่มี webhook พิมพ์ผิดนิดเดียวก็จะไม่มีใครรู้ จนกว่า kubelet plugin จะเตรียม device ไม่ผ่าน แล้ว pod ค้างอยู่ที่ ContainerCreating
ลองเทียบกับเช็กเรื่อง sharing ในหน้า conformance ที่ใช้ time-slicing ของ device plugin ซึ่งตั้ง replica count ค่าเดียวทั้ง node ใช้กับทุก pod1 DRA ย้ายการตัดสินใจนี้มาอยู่ที่แต่ละ claim บน node เดียวกัน GPU ใบหนึ่งแบ่ง 4 ส่วนให้ notebook ได้ ส่วนใบข้าง ๆ ให้ training ใช้คนเดียวก็ได้
Step 7: ให้ pod ที่ขอ nvidia.com/gpu ยังรันได้แม้ไม่มี device plugin¶
ใน chart 0.4.1 DeviceClass gpu.nvidia.com จะตั้ง extendedResourceName: nvidia.com/gpu ให้ ถ้า cluster มี resource.k8s.io/v19 และใน 1.36 DRAExtendedResource เป็น beta ที่เปิดอยู่แล้ว2 pod เดิมที่ไม่ได้แก้อะไรเลยแบบนี้:
…ก็ได้ GPU จาก DRA บน node ที่ปิด device plugin ไว้ได้ โดย scheduler สร้าง claim ให้ pod เอง KEP-5004 คือสะพานที่ทำให้ปิด device plugin ได้เลย ไม่ต้องรอให้ Helm chart ทุกตัวใน catalog รองรับ ResourceClaim ก่อน4
ก่อนจะพึ่งทางนี้ให้ลองบน cluster ตัวเองก่อน เพราะหน้า conformance ไม่ได้ทดสอบ path นี้:
kubectl get pod <pod> -o jsonpath='{.status.extendedResourceClaimStatus}' | jq
kubectl get resourceclaims -n <ns>
ควรเห็น claim ที่ scheduler สร้างให้ พร้อม device gpu-N ที่ allocate แล้ว
Step 8: Claim หลาย GPU และ topology¶
ขอ GPU 2 ใบที่อยู่บน PCIe root complex เดียวกัน ใช้ทำ tensor parallelism โดยไม่ต้องวิ่งข้าม CPU interconnect:
devices:
requests:
- name: gpus
exactly:
deviceClassName: gpu.nvidia.com
count: 2
constraints:
- requests: ["gpus"]
matchAttribute: resource.kubernetes.io/pcieRoot
เหมา GPU ทุกใบบน node (เช่น training job ที่ต้องการ node ทั้งตัว หรือรัน burn-in test):
ถ้า node ที่ scheduler เล็งไว้มี GPU ใบไหนโดน claim ไปแล้ว allocationMode: All จะไม่ผ่าน โหมดนี้มีไว้ใช้กับ node ที่ว่างทั้งตัว ไม่ได้แปลว่า "ได้เท่าไหร่เอาเท่านั้น"
Step 9: MIG บน pool ที่ทำ MIG ได้¶
A40 ทำ MIG ไม่ได้ แต่ถ้า NKP cluster มี pool ของ H100 หรือ A100 เพิ่มเข้ามา mig.nvidia.com จะเห็น instance ที่แบ่งไว้แล้ว ต้องแบ่ง partition ด้วย nvidia-mig-parted (หรือ MIG manager ของ GPU Operator) ไว้ก่อน ถ้าอยากให้สร้างตอนขอ ต้องเปิด gate DynamicMIG10
ขอ slice 1g.10gb 2 ชิ้นจาก GPU ใบจริงใบเดียวกัน:
devices:
requests:
- name: mig-a
exactly:
deviceClassName: mig.nvidia.com
selectors:
- cel:
expression: "device.attributes['gpu.nvidia.com'].profile == '1g.10gb'"
- name: mig-b
exactly:
deviceClassName: mig.nvidia.com
selectors:
- cel:
expression: "device.attributes['gpu.nvidia.com'].profile == '1g.10gb'"
constraints:
- requests: []
matchAttribute: gpu.nvidia.com/parentUUID
แต่ละ container เลือก slice ด้วย claims: [{name: <claim>, request: mig-a}] เหมือน gpu-test4 ของ upstream12
Step 10: Passthrough และ ComputeDomain¶
DeviceClass สองตัวนี้มีในทุก NKP 2.19 cluster แต่วันแรกแทบไม่มีใครได้ใช้
vfio.gpu.nvidia.com เอาไว้ bind GPU กับ vfio-pci ให้ VM (KubeVirt) ใช้ ต้องเปิด gate PassthroughSupport10 แต่บน NKP ที่เจอบ่อยกว่าคือทำ AHV GPU passthrough เข้า worker VM ไปเลย conformance node ก็ใช้แบบนี้ (nvidia.com/gpu.machine=AHV)1
ComputeDomain สร้าง Multi-Node NVLink domain ที่ปลอดภัยให้ pod บนระบบระดับ GB200 driver จะรัน IMEX daemon หนึ่งตัวต่อ domain แล้ว inject channel เข้าไปใน pod:14
apiVersion: resource.nvidia.com/v1beta1
kind: ComputeDomain
metadata:
name: training-domain
namespace: dra-demo
spec:
numNodes: 2
channel:
resourceClaimTemplate:
name: training-domain-channel
จากนั้นใน pod ก็ใส่ resourceClaimTemplateName: training-domain-channel ควบคู่กับ GPU claim ปกติ ถ้าเป็น PCIe GPU อย่าง A40 pod พวกนี้ก็จะค้าง Pending อยู่อย่างนั้น
Step 11: Guardrail — quota, admin access, taint¶
จำกัดจำนวน GPU ต่อ namespace¶
DRA มี quota key แยกตาม DeviceClass ตัวอย่างนี้จำกัดทีมไว้ที่ GPU ทั้งใบ 2 ใบ:6
apiVersion: v1
kind: ResourceQuota
metadata:
name: gpu-quota
namespace: team-a
spec:
hard:
gpu.nvidia.com.deviceclass.resource.k8s.io/devices: "2"
ถ้าสร้าง custom class ไว้ (Step 4) ก็เพิ่มบรรทัดละ class ตั้ง quota ที่ nvidia.com/gpu อย่างเดียว คุม claim ที่ขอผ่าน DeviceClass ตรง ๆ ไม่ได้
ให้ monitoring เห็น GPU ทุกใบ¶
Admin access เป็น stable แล้วใน 1.362 ทำให้ pod เข้าไปเกาะ device ที่ allocate ให้คนอื่นไปแล้วได้ เอาไว้ debug หรือทำ health check โดยไม่ไปกินโควตา device นั้น ใช้ได้เฉพาะ namespace ที่ติด label นี้:7
apiVersion: v1
kind: Namespace
metadata:
name: gpu-ops
labels:
resource.kubernetes.io/admin-access: "true"
---
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: all-gpus-admin
namespace: gpu-ops
spec:
spec:
devices:
requests:
- name: gpus
exactly:
deviceClassName: gpu.nvidia.com
allocationMode: All
adminAccess: true
ล็อก label นี้ไว้ด้วย RBAC หรือ admission policy เพราะใครติด label ให้ namespace ได้ ก็เข้าถึง GPU ของทุก tenant ได้
ถอด GPU ที่เสียออก ไม่ต้อง drain ทั้ง node¶
ใน 1.36 device taint เป็น beta และเปิดอยู่แล้ว2 device ที่ติด taint จะไม่ถูกเลือกให้ claim ใหม่ ยกเว้น request นั้น tolerate ไว้ ส่วน object DeviceTaintRule ที่ admin ใช้ยังปิด gate ไว้เป็น default ใน 1.36 บน NKP 2.19 taint เลยมาจาก driver อย่างเดียว เปิด NVMLDeviceHealthCheck (Step 2) ไว้ แล้ว driver จะ flag GPU ที่ไม่ healthy ให้เอง10
Step 12: ใช้ DRA เช็ก driver¶
ข้อกำหนด conformance เรื่อง driver runtime management ให้ platform เช็ก driver ผ่าน DRA ถ้า accelerator รองรับ บน NKP ใน ResourceSlice มี driverVersion อยู่แล้ว และตรงกับ node label nvidia.com/cuda.driver-version.full=580.126.181
เอาค่านี้มาทำ fleet check ตอน upgrade NKP ได้ ให้ flag GPU ทุกใบที่ driver ยังไม่ใช่เวอร์ชันเป้าหมาย:
TARGET=580.126.18
kubectl get resourceslices -o json | jq -r --arg t "$TARGET" '
.items[] | select(.spec.driver == "gpu.nvidia.com")
| .spec.nodeName as $n | .spec.devices[]
| select(.attributes.driverVersion.version != $t)
| "\($n)\t\(.name)\t\(.attributes.driverVersion.version)"'
ถ้า output ว่าง แปลว่า GPU ทุกใบตรงหมด claim ไหนที่ห้ามไปลง node ที่ upgrade ค้างครึ่งทาง ก็ใส่ CEL selector เช็ก driverVersion ไว้
Troubleshooting¶
| อาการ | สาเหตุที่น่าจะเป็น | เช็กอะไร |
|---|---|---|
Pod Pending, มี event cannot allocate all claims | ไม่มี device ว่างที่ตรงกับ request | kubectl get resourceslices -o yaml; ผ่อน CEL; ดูว่ามี claim อื่นถือ GPU อยู่ไหม |
| Pod Pending, ไม่มี DRA event เลย | Claim อ้าง DeviceClass ที่ไม่มีอยู่จริง | kubectl get deviceclasses |
ไม่เห็น gpu.nvidia.com ใน DeviceClass | Chart render ออกมาไม่มี GPU resource (ติด override guard) | HelmRelease values: resources.gpus.enabled, gpuResourcesEnabledOverride |
| GPU node ไม่มี ResourceSlice | Kubelet plugin ไม่ได้ไปลงที่ node นั้น หรือตั้ง driver root ผิด | kubectl get pods -n kommander -o wide \| grep kubelet-plugin; nvidiaDriverRoot ใช้ / ถ้า driver ลงบน host และ /run/nvidia/driver ถ้า operator จัดการ driver |
Pod ค้าง ContainerCreating | Kubelet plugin เตรียม device ไม่ผ่าน (opaque config ผิด หรือ gate ปิด) | kubectl describe pod; log ของ kubelet plugin |
| Claim โดน reject ตอน admission | Webhook ไม่รับ GpuConfig ส่วนใหญ่เพราะใช้ฟีเจอร์ที่ gate ยังปิด | เปิด driver gate; kubectl logs deploy/dra-driver-nvidia-gpu-webhook -n kommander |
| สอง pod เห็น GPU ใบเดียวกันโดยไม่ได้ตั้งใจ | เปิดทั้ง device plugin และ DRA บน node นั้น | Label nvidia.com/gpu.deploy.device-plugin; Step 2 |
| Pod priority สูงไม่ยอม preempt | DRA ไม่มี preemption | ปกติ; ต้องปล่อย device เอง5 |
Manifest validate ไม่ผ่านตรง deviceClassName | ใช้ syntax ของ v1beta1 ที่ไม่มี exactly: | ครอบ request ด้วย exactly: |
เรื่องที่ผมยังยืนยันไม่ได้¶
- Override hook ของ NKP สำหรับ
nvidia-dra-driverชื่อจริงคืออะไร หน้า conformance แสดงวิธีใช้ ConfigMap ไว้แค่กับ GPU Operator ให้ใช้คำสั่ง lookupvaluesFromใน Step 2 ดูชื่อจริงบน cluster ตัวเอง - Extended resource mapping ใช้ได้ครบทั้งเส้นบน NKP ไหม Chart ตั้ง
extendedResourceNameไว้ และ gate ของ 1.36 ก็เปิดอยู่ แต่หน้า conformance ไม่ได้ schedule pod ผ่านทางนี้ ทดสอบให้ผ่านก่อนค่อยถอด device plugin - ค่า capacity
memoryที่ A40 publish จริง หน้านั้นแสดงแค่ attribute ไม่ได้แสดง capacity ตัวเลข 46068Mi ใน Step 1 คำนวณมาจาก node labelnvidia.com/gpu.memory - Driver เวอร์ชันที่ใหม่กว่าบน NKP ตอนนี้ docs ของ NVIDIA พูดถึง DRA driver v0.5.1 กับ GPU Operator v26.7.2 แล้ว และระบุว่า full-GPU allocation เป็น generally available13 แต่ NKP 2.19 pin ไว้ที่ 0.4.1 ดู release note ของ NKP ก่อน อย่าเพิ่งคิดว่าพฤติกรรมจะเหมือน 0.5.x
สรุป¶
กฎมีข้อเดียว: หนึ่ง node ใช้ GPU allocation path เดียว ใช้ DRA เป็นหลัก และใช้ claim ทุกที่
| ถ้าต้องการ… | ใช้ | Gate |
|---|---|---|
| GPU ส่วนตัวหนึ่งใบต่อ pod | ResourceClaimTemplate → gpu.nvidia.com | ไม่ต้อง |
| เอาเฉพาะ GPU ที่มี ≥ N GiB หรือ driver ขั้นต่ำ | CEL selector หรือ custom DeviceClass | ไม่ต้อง |
| "มี H100 ก็เอา H100 ไม่มีก็ A40" | firstAvailable | ไม่ต้อง (stable ใน 1.36) |
| หลาย container ใช้ GPU ใบเดียว | Claim เดียว อ้างจากหลายที่ | ไม่ต้อง |
| แชร์แบบจำกัด resource | GpuConfig MPS | MPSSupport |
| แยกกันระดับ hardware | mig.nvidia.com บน H100/A100 | ไม่ต้อง (static MIG) |
Chart เก่าที่ขอ nvidia.com/gpu | Extended resource mapping | ไม่ต้อง (beta, เปิดอยู่ใน 1.36) |
| จำกัด GPU ต่อทีม | Quota gpu.nvidia.com.deviceclass.resource.k8s.io/devices | ไม่ต้อง |
| Monitoring ที่เห็นทุก tenant | adminAccess: true + namespace ที่ติด label | ไม่ต้อง (stable ใน 1.36) |
Production checklist สำหรับ DRA บน NKP 2.19:
- เช็ก API, DeviceClass, ResourceSlice และ driver pod แล้ว (Step 1)
- ปิด device plugin บนทุก node ที่รัน DRA GPU plugin
- Override ค่าของ driver ผ่าน
valuesFromConfigMap ของ HelmRelease ไม่ใช้kubectl edit - Manifest ใหม่ทุกตัวใช้
resource.k8s.io/v1คู่กับexactly:หรือfirstAvailable: - มี custom DeviceClass ตาม hardware tier
- ทุก tenant namespace มี ResourceQuota ราย DeviceClass
- ใช้ RBAC คุมว่าใครติด label
resource.kubernetes.io/admin-accessได้ - ทดสอบ extended resource mapping แล้ว ก่อนเลิกใช้
nvidia.com/gpu - ออกแบบการแบ่ง GPU ที่เคยพึ่ง preemption ใหม่แล้ว (DRA ไม่มี preemption)
- ใส่การเช็ก driver version จาก ResourceSlice ไว้ใน upgrade runbook แล้ว
ถ้าอยากดู walkthrough แบบทั่วไปที่ไม่ผูกกับ NKP ว่าย้ายออกจาก device plugin ยังไง ไปที่ GPU DRA บน Kubernetes: ย้ายออกจาก NVIDIA device plugin
-
Nutanix, CNCF AI Conformance — NKP 2.19 — ทดสอบบน NKP 2.19.0-dev.34, Kubernetes v1.36.2, GPU Operator v26.3.3,
dra-driver-nvidia-gpu@0.4.1, NVIDIA A40, driver 580.126.18, containerd 2.3.1-d2iq.1 ↩↩↩↩↩↩↩↩↩↩↩↩↩ -
Kubernetes, Feature Gates — stage ของ DRA gate ในแต่ละ release (เข้าถึงเมื่อ 2026-11-05) ↩↩↩↩↩
-
Kubernetes Blog, Kubernetes v1.34: DRA has graduated to GA. ↩
-
Kubernetes Blog, Kubernetes v1.36: More Drivers, New Features, and the Next Era of DRA — 2026-05-07 ↩↩↩
-
Kubernetes, Dynamic Resource Allocation — หัวข้อ "Limitations": DRA resource ไม่มี preemption ↩↩
-
Kubernetes, Resource Quotas — quota ราย DeviceClass สำหรับ DRA ↩
-
Kubernetes, Allocate devices to workloads using DRA — admin access และ namespace label
resource.kubernetes.io/admin-access↩ -
kubernetes-sigs, dra-driver-nvidia-gpu README at v0.4.1. ↩
-
kubernetes-sigs, dra-driver-nvidia-gpu Helm chart templates at v0.4.1 —
deviceclass-*.yaml,validation.yaml↩↩↩ -
kubernetes-sigs, pkg/featuregates/featuregates.go at v0.4.1. ↩↩↩↩
-
kubernetes-sigs, cmd/gpu-kubelet-plugin/deviceinfo.go at v0.4.1. ↩
-
kubernetes-sigs, demo/specs/quickstart/v1 at v0.4.1 —
gpu-test2,gpu-test4,gpu-test5,gpu-test-mps↩↩↩ -
NVIDIA, NVIDIA DRA Driver for GPUs — เอกสารของ GPU Operator (หน้าปัจจุบันพูดถึง driver v0.5.1 กับ GPU Operator v26.7.2) ↩↩
-
NVIDIA, GPU Operator — DRA ComputeDomains. ↩
-
NVIDIA, GPU Operator — Common Deployment Scenarios — label
nvidia.com/gpu.deploy.<component>ราย node ↩
Discussion
Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.