Stage 12, Part 1 of 9 · p. 101, GPU Orchestration & Multi-Tenancy

PART 1: CORE THEORY

1. The GPU Orchestration Problem

GPUs are the most expensive and most wasted resource in modern Kubernetes clusters. A single H100 node can run well over $30/hour in the cloud. The average GPU utilization in enterprise Kubernetes clusters sits at 5%, according to a Cast AI 2026 report measuring 23,000 clusters.

Why GPUs Are Different

AspectCPUGPU
GranularityMillicoresWhole devices (unless shared)
SharingNative (time-slicing by kernel)Requires explicit configuration
Cost$0.05–$0.50/core/hour$2–$30+/GPU/hour
IsolationProcess-levelDevice-level (unless MIG)
MemoryNot a resourceCritical resource (VRAM)

The Default Model

The NVIDIA device plugin advertises GPUs as integer resources (nvidia.com/gpu). When a pod requests nvidia.com/gpu: 1, Kubernetes schedules it onto a node with an available GPU and treats that device as allocated. One pod = one GPU.

This creates a GPU waste tax for inference workloads: ten services that each use 15% of a GPU still need ten physical GPUs with full-GPU allocation. The real demand is closer to 1.5 GPUs, but Kubernetes still reserves ten devices unless sharing is configured.

The Three Layers of GPU Management

LayerPurposeTools
Device ExposureMake GPUs available to KubernetesNVIDIA Device Plugin, DRA
SchedulingPlace pods on GPU nodesDefault scheduler, KAI, Kueue
Sharing/IsolationMultiple workloads per GPUTime-slicing, MPS, MIG, DRA

2. NVIDIA Device Plugin

The NVIDIA Device Plugin is the foundation of GPU orchestration. It registers GPUs as compute resources in the Kubernetes cluster and manages their allocation.

How the Device Plugin Works

text
┌─────────────────────────────────────────────────────────────┐
│                    NVIDIA DEVICE PLUGIN FLOW                │
│                                                             │
│  1. Plugin starts on GPU node (DaemonSet)                  │
│  2. Detects GPUs via NVML                                  │
│  3. Registers with kubelet via Device Plugin API           │
│  4. Kubelet advertises "nvidia.com/gpu" as extended resource│
│  5. Scheduler sees GPU as allocatable resource             │
│  6. Pod requests nvidia.com/gpu: N                         │
│  7. Device plugin allocates N GPUs to the pod              │
│  8. Container runtime exposes devices to container         │
└─────────────────────────────────────────────────────────────┘

Installation (GPU Operator)

The recommended way to install the device plugin is via the NVIDIA GPU Operator:

bash
# Add NVIDIA Helm repository
helm repo add nvidia https://helm.ngc.nvidia.com/nvidia
helm repo update

# Install GPU Operator
helm install gpu-operator nvidia/gpu-operator \
  --namespace gpu-operator \
  --create-namespace \
  --set driver.enabled=true \
  --wait

# Verify
kubectl get pods -n gpu-operator
kubectl get nodes -l nvidia.com/gpu.present=true

Verifying GPU Detection

bash
# Check GPU resources on nodes
kubectl describe node <gpu-node-name> | grep nvidia.com/gpu
# Should show something like: nvidia.com/gpu: 4

What the GPU Operator Manages

ComponentPurpose
DriverNVIDIA kernel modules
Container ToolkitExposes GPUs to containers
Device PluginRegisters GPUs with kubelet
DCGM ExporterGPU metrics
MIG ManagerMIG partition management
Node Feature DiscoveryLabels nodes with GPU model

2026: CDI Injection Mode

NVIDIA's OpenShell project switched device plugin to CDI (Container Device Interface) injection mode in March 2026. CDI is the modern standard for exposing devices to containers, replacing the older device mount approach.

Latest Version (2026)

NVIDIA k8s-device-plugin v0.20.0 (August 2026) adds:


3. GPU Scheduling in Kubernetes

The Default Scheduling Model

GPUs are advertised as extended resources (nvidia.com/gpu). The scheduler treats them as integer counts.

yaml
apiVersion: v1
kind: Pod
metadata:
  name: gpu-pod
spec:
  containers:
  - name: cuda-app
    image: nvidia/cuda:12.0-base
    resources:
      limits:
        nvidia.com/gpu: 1        # Request 1 GPU

Key constraint: GPUs are only available in limits, not requests. Requesting a GPU implicitly sets the request equal to the limit.

GPU Node Pools

Production clusters use dedicated GPU node pools with:

ConfigurationPurpose
TaintKeep non-GPU workloads off GPU nodes
LabelIdentify GPU type/model
Node selector/affinityTarget specific GPU types
yaml
# Taint GPU nodes
kubectl taint nodes gpu-node-1 nvidia.com/gpu=present:NoSchedule

# Label GPU nodes
kubectl label nodes gpu-node-1 nvidia.com/gpu.product=NVIDIA-A100-SXM4-40GB
kubectl label nodes gpu-node-1 nvidia.com/gpu.memory=40960

Pod Scheduling for GPUs

yaml
apiVersion: v1
kind: Pod
metadata:
  name: gpu-workload
spec:
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  nodeSelector:
    nvidia.com/gpu.product: NVIDIA-A100-SXM4-40GB
  containers:
  - name: training
    image: pytorch/pytorch:2.0-cuda11.7
    resources:
      limits:
        nvidia.com/gpu: 4        # Request 4 GPUs

GPU Scheduling Limitations

LimitationImpact
Integer-onlyNo fractional GPUs
No topology awarenessScheduler doesn't know NVLink
No attribute-based schedulingCan't request GPU with >40GB VRAM
No sharingUnless explicitly configured

These limitations are addressed by DRA (Dynamic Resource Allocation).


4. GPU Sharing Strategies

The three main NVIDIA-supported options are time-slicing, Multi-Process Service (MPS), and Multi-Instance GPU (MIG). Each solves the sharing problem differently.

Comparison

AspectTime-SlicingMPSMIG
MechanismSoftware (CUDA context switching)Software (CUDA concurrency)Hardware (GPU partitioning)
Isolation❌ None⚠️ Limited✅ Full (dedicated SM + memory)
GPU SupportMost NVIDIA GPUsMost NVIDIA GPUsA100, A30, H100, H200+
Memory Isolation❌ No❌ No✅ Yes
Fault Isolation❌ No❌ No✅ Yes
ConfigurationSimpleMediumComplex
Best ForDev, non-criticalTrusted CUDAProduction, multi-tenant

Time-Slicing

Time-slicing lets GPU processes take turns on a single physical device via CUDA context switching. It's the simplest way to share a GPU.

Configuration:

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: time-slicing-config
  namespace: gpu-operator
data:
  any: |
    version: v1
    flags:
      migStrategy: none
    sharing:
      timeSlicing:
        resources:
        - name: nvidia.com/gpu
          replicas: 4
bash
# Update GPU Operator
helm upgrade gpu-operator nvidia/gpu-operator \
  --namespace gpu-operator \
  --set devicePlugin.config.name=time-slicing-config \
  --set devicePlugin.config.default=any \
  --reuse-values

# Verify (4 physical GPUs → 16 advertised)
kubectl describe node <gpu-node> | grep nvidia.com/gpu
# Should show: nvidia.com/gpu: 16

Key limitation: Time-slicing does not isolate memory or faults. One workload's memory pressure or CUDA fault can affect another tenant.

MPS (Multi-Process Service)

MPS improves concurrency for trusted CUDA workloads by allowing multiple processes to share the GPU's compute resources more efficiently than time-slicing.

When to use MPS: Multiple trusted workloads that need concurrent GPU access (e.g., multiple inference services from the same team).

Key limitation: A single client fault can affect other clients sharing the GPU.

MIG (Multi-Instance GPU)

MIG creates hardware-isolated GPU partitions. Each partition has its own SM (Stream Multiprocessor) and GPU memory.

MIG-capable GPUs: A100, A30, H100, H200, and newer MIG-capable data center GPUs.

GPUMax MIG Instances
A100 (40GB)7
A100 (80GB)7
H100 (80GB)7
H2007

When to use MIG: Production multi-tenant environments where performance guarantees and fault isolation are required.


1:1 copy of the class Google Doc, code in code blocks.