Stage 12, Part 6 of 9, GPU Orchestration & Multi-Tenancy

Text

PART 6: HANDS-ON LABS

Lab 1: Install GPU Operator and Verify GPUs

bash
# Install GPU Operator
helm repo add nvidia https://helm.ngc.nvidia.com/nvidia
helm repo update
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

# Check GPU resources
kubectl describe node <gpu-node> | grep nvidia.com/gpu

Lab 2: Configure GPU Time-Slicing

bash
# Create ConfigMap
cat <<'EOF' | kubectl apply -f -
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
EOF

# 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
kubectl describe node <gpu-node> | grep nvidia.com/gpu
# Should show 4x capacity

Lab 3: Configure MIG Partitioning

bash
# Create MIG ConfigMap
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: mig-config
  namespace: gpu-operator
data:
  config.yaml: |
    version: v1
    mig-configs:
      all-1g.5gb:
        - devices: all
          mig-enabled: true
          mig-devices:
            "1g.5gb": 7
EOF

# Apply
helm upgrade gpu-operator nvidia/gpu-operator \
  --namespace gpu-operator \
  --set migManager.config.name=mig-config \
  --reuse-values

# Verify MIG
kubectl describe node <gpu-node> | grep nvidia.com/mig

Lab 4: Deploy DCGM Exporter and Monitor GPUs

bash
# DCGM is deployed by GPU Operator
kubectl get pods -n gpu-operator -l app=nvidia-dcgm-exporter

# Port-forward
kubectl port-forward -n gpu-operator svc/nvidia-dcgm-exporter 9400:9400

# Check metrics
curl localhost:9400/metrics | grep DCGM_FI_DEV_GPU_UTIL

Lab 5: GPU Multi-Tenancy

bash
kubectl create namespace team-a
kubectl create namespace team-b

# ResourceQuota for team-a
cat <<'EOF' | kubectl apply -n team-a -f -
apiVersion: v1
kind: ResourceQuota
metadata:
  name: gpu-quota
spec:
  hard:
    requests.nvidia.com/gpu: "2"
    limits.nvidia.com/gpu: "2"
EOF

# Deploy GPU pod in team-a
cat <<'EOF' | kubectl apply -n team-a -f -
apiVersion: v1
kind: Pod
metadata:
  name: gpu-pod
spec:
  containers:
  - name: app
    image: nvidia/cuda:12.0-base
    command: ["nvidia-smi"]
    resources:
      limits:
        nvidia.com/gpu: 1
EOF

Lab 6: GPU Cost Optimization

yaml
# Spot node pool
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: gpu-spot
spec:
  template:
    spec:
      requirements:
      - key: karpenter.sh/capacity-type
        operator: In
        values: ["spot"]
      - key: node.kubernetes.io/instance-type
        operator: In
        values: ["p4d.24xlarge"]
  limits:
    nvidia.com/gpu: 8

Lab 7: Schedule GPU Workloads

yaml
apiVersion: v1
kind: Pod
metadata:
  name: gpu-training
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

Lab 8: Debug GPU Scheduling Failures

bash
# Create a pod requesting too many GPUs
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: impossible-gpu
spec:
  containers:
  - name: app
    image: nvidia/cuda:12.0-base
    resources:
      limits:
        nvidia.com/gpu: 100
EOF

sleep 10
kubectl describe pod impossible-gpu | grep -A10 Events

# Cleanup
kubectl delete pod impossible-gpu

Lab 9: End-to-End GPU Inference Platform

bash
# Deploy vLLM with GPU
cat <<'EOF' | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: vllm
  template:
    metadata:
      labels:
        app: vllm
    spec:
      containers:
      - name: vllm
        image: vllm/vllm-openai:latest
        args: ["--model", "meta-llama/Llama-2-7b-hf"]
        resources:
          limits:
            nvidia.com/gpu: 1
        ports:
        - containerPort: 8000
---
apiVersion: v1
kind: Service
metadata:
  name: vllm
spec:
  selector:
    app: vllm
  ports:
  - port: 8000
EOF

# Test
kubectl port-forward svc/vllm 8000:8000
curl http://localhost:8000/v1/models

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