Phase 05/Moving bytes between GPUs and nodes/Kubernetes GPU scheduling
PHASE 05 · Moving bytes between GPUs and nodes

Kubernetes GPU scheduling

0%
8 h5 subtopics2 lessons · 2 required
In plain English

A company with hundreds of GPUs does not hand them out by email. It uses a scheduler, almost always Kubernetes, that treats GPUs like seats in a theatre. Each program asks for a number of seats, the scheduler finds a machine with enough free ones, and it refuses to double-book. For distributed inference the request is more specific. A model split across eight GPUs needs eight seats in the same row (one node, meaning one physical server, whose GPUs are linked by fast NVLink), and a model split across machines needs several rows reserved at the same moment or none at all (gang scheduling). This topic covers how GPUs are advertised to Kubernetes, how to ask for them, how to keep the wrong workloads off GPU nodes, and how to launch multi-node serving jobs that start together.

Why it matters

Nearly all production inference runs on Kubernetes. Knowing the device plugin, resource requests, taints, and gang scheduling means you can deploy vLLM to a cluster, debug Pending pods, and avoid stranding expensive GPUs.

Hiring signal

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Cursor, Databricks, Fireworks, Modal, nvidia, OpenAI, Perplexity, Poolside, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Explain how the NVIDIA device plugin advertises nvidia.com/gpu as an extended resource.
  • Write a Deployment that requests GPUs, pins to GPU nodes with selectors and tolerations, and exposes a serving endpoint.
  • Use node labels, taints, and topology spread to place TP workloads on NVLink nodes and keep CPU workloads off GPU nodes.
  • Describe gang scheduling and the LeaderWorkerSet or Ray-based patterns for multi-node vLLM.

Key concepts

Device plugin
A DaemonSet that discovers GPUs on each node and reports them to the kubelet as nvidia.com/gpu.
Extended resource
A countable non-CPU/memory resource that a pod requests in limits; GPUs are integers and cannot be overcommitted.
Taint and toleration
A node taint repels pods; only pods with a matching toleration may schedule there, keeping GPU nodes for GPU jobs.
Node affinity and labels
Selecting nodes by labels such as GPU model or NVLink presence.
Gang scheduling
Scheduling all pods of a multi-node job atomically so partially started jobs do not deadlock the cluster.
MIG and time-slicing
Ways to carve one GPU into smaller schedulable units for small models.
LeaderWorkerSet
A Kubernetes API for groups of pods (leader plus workers) that start and scale together, used for multi-node vLLM.

Subtopics

  1. 1. How Kubernetes sees a GPU

    NVIDIA device plugin and GPU Operator, nvidia.com/gpu resource, drivers and container toolkit on the node.

  2. 2. Requesting GPUs in a pod spec

    resources.limits, integer-only requests, one container per GPU set, environment variables injected by the runtime.

  3. 3. Placement controls

    Labels, nodeSelector, affinity, taints and tolerations, topologySpreadConstraints; keeping TP groups on one node.

  4. 4. Multi-node serving jobs

    Gang scheduling with Kueue or Volcano, LeaderWorkerSet, Ray on Kubernetes; headless services for rank discovery.

  5. 5. Sharing and fractional GPUs

    MIG profiles, time-slicing, and when a small model should share a GPU.

Resources

Hands-on lessons

L1

Fake GPU scheduling on kind

CPU · your Maccli150 minrequired

Goal · A local kind cluster where some nodes advertise a fake extended resource and are tainted, and you prove the scheduler places and rejects pods exactly as it would with real GPUs.

  1. 1Install kind and kubectl; create a cluster with one control-plane and three worker nodes from a kind config file.
  2. 2Label two workers accelerator=fake-gpu and taint them nvidia.com/gpu=present:NoSchedule; leave the third as a CPU node.
  3. 3Advertise a fake extended resource by patching node status via the API server proxy (kubectl proxy, then PATCH /api/v1/nodes/NAME/status with capacity example.com/gpu 4).
  4. 4Write a Deployment that requests example.com/gpu 2 with the matching toleration and nodeSelector; scale to 4 replicas and observe where they land.
  5. 5Scale to 5 replicas and show with kubectl describe pod that the fifth is Pending with an insufficient example.com/gpu event.
  6. 6Deploy a plain CPU pod without the toleration and confirm it never lands on a tainted node.
  7. 7Add a podAntiAffinity or topologySpreadConstraint and show replicas spread across both fake-GPU nodes.
Deliverable
kind-config.yaml, the manifests, and a transcript of kubectl get pods -o wide plus the Pending event.
Check
Exactly four replicas are Running (two per fake-GPU node); the fifth is Pending with an insufficient resource message; the CPU pod runs only on the untainted node.
L2

Design a multi-node vLLM deployment manifest

CPU · your Macdesign90 minrequired

Goal · A reviewed LeaderWorkerSet or StatefulSet manifest plus headless Service that would run Llama-3-70B with TP=8 and PP=2 across two 8-GPU nodes, with the rank discovery and gang-scheduling story written down.

  1. 1Read the LeaderWorkerSet vLLM example and the vLLM multi-node docs; list every environment variable and port needed for ranks to find each other.
  2. 2Write a LeaderWorkerSet with size 2, nvidia.com/gpu 8 per pod, a toleration for the GPU taint, and a nodeAffinity on a label marking NVLink nodes.
  3. 3Add a headless Service and readiness probe on /health; explain why the leader must wait for the worker before starting the engine.
  4. 4Describe what happens without gang scheduling when only one node has 8 free GPUs and how Kueue or Volcano prevents it.
  5. 5Validate the manifest with kubectl apply --dry-run=client on your kind cluster (it will not run but must parse).
Deliverable
lws-vllm-70b.yaml and a one-page design note covering discovery, probes, and gang scheduling.
Check
kubectl apply --dry-run=client passes; the design note answers how rank 1 learns the leader address and what blocks a partial start.

Build your own

Build your own GPU scheduler simulator

PythonCPU · your Mac~7 h

A kube-scheduler lookalike that filters and scores nodes for pods with GPU and memory requests, gang-schedules TP groups and measures fragmentation, checked against a kind cluster with fake GPUs.

The real thing: github.com/kubernetes/kubernetes/tree/master/pkg/scheduler/framework/plugins/noderesources ↗

How you know a stage passes

Write tests/test_scheduler.py first. Scenarios live in tests/scenarios/*.yaml as node lists, pod lists and expected placements; the simulator CLI `sched run <scenario>` prints placements and metrics as JSON that the tests compare exactly. The final stage runs a script that applies the same scenarios to a kind cluster and diffs `kubectl get pods -o wide` against the simulator. Run `pytest -q`.

Stages, in order. Each one leaves you with something that runs.0/6
  1. 01resources and the filter phase
    Nodes carry allocatable cpu, memory and nvidia.com/gpu; pods carry requests; the filter returns the feasible nodes or marks the pod Pending with a reason string.
    test · A pod requesting 2 GPUs is rejected on a node with 1 free; with no feasible node the pod is Pending with reason Insufficient nvidia.com/gpu; scenario 01 matches expected output exactly.
  2. 02scoring and fragmentation
    LeastAllocated and MostAllocated scoring pick among feasible nodes; a fragmentation metric counts free GPUs that cannot host any pending pod.
    test · MostAllocated places eight 1-GPU pods on one 8-GPU node and leaves the second empty, LeastAllocated splits them 4/4; a following 8-GPU pod schedules only under MostAllocated and the fragmentation metric is 0 versus 8.
  3. 03taints, selectors and anti-affinity
    Taints with tolerations, nodeSelector labels and required pod anti-affinity on a topology key participate in filtering.
    test · A pod without the nvidia.com/gpu toleration never lands on a tainted GPU node; three replicas with anti-affinity on kubernetes.io/hostname spread across three nodes and a fourth goes Pending.
  4. 04gang scheduling for TP and PP groups
    A PodGroup with minMember is placed atomically; partial placement is never committed and a group waits with reason until all members fit.
    test · With two nodes each having 4 GPUs free a TP=8 group stays Pending with zero members bound; two TP=4 groups both bind; a scenario where two half-placed groups would deadlock under naive scheduling completes under yours.
  5. 05trace replay over time
    An arrival and departure trace of mixed 1, 2, 4 and 8 GPU jobs runs through the scheduler, recording utilisation, queue wait and fragmentation per minute for each scoring policy.
    test · On the mixed trace MostAllocated achieves at least 10 percent higher mean GPU utilisation than LeastAllocated and lower median queue wait; results.csv and a plot are written.
  6. 06the kind manifest set and the diff
    A kind config with two workers advertising example.com/gpu 4 (status patch plus taint), Deployment and StatefulSet manifests with resource requests, tolerations and anti-affinity, and a script that replays three scenarios on kind and diffs placements against the simulator.
    test · Placements on kind equal the simulator's for all three scenarios; a pod requesting 5 example.com/gpu stays Pending and `kubectl describe pod` shows FailedScheduling with Insufficient example.com/gpu.

Knowledge check

QWhy can a pod not request 0.5 of nvidia.com/gpu?

Extended resources are integers and GPUs are not overcommittable; fractional sharing requires MIG or time-slicing which present separate resources.

QWhat combination keeps non-GPU workloads off expensive GPU nodes?

Taint the GPU nodes with NoSchedule and add tolerations only to GPU pods.

QWhy does a two-node tensor/pipeline-parallel job need gang scheduling?

If only one pod schedules it holds 8 GPUs idle waiting for a partner that may never fit, deadlocking capacity; gang scheduling admits all pods or none.

QHow does a worker pod find the leader in a LeaderWorkerSet?

Through a stable DNS name provided by the headless Service and injected environment variables with the leader address and group size.

Completion

  • All 5 subtopics marked done
  • All 2 required lessons done
  • Lesson l1 kind cluster transcript shows correct placement and a Pending pod.
  • Lesson l2 manifest passes dry-run and the design note is complete.
  • Can explain the device plugin, taints, and gang scheduling without notes.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →