20.7.2 Weight staging and deployment
This part of Deploying LLMs on Kubernetes: GPUs, Replicas, and Rollouts develops the worked mechanisms below.
Concepts from other sections (10)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- cold start: the time from scheduling a replica to serving its first request, dominated by fetching and reading weight bytes and then by engine initialization. Read more: 20.3.4 Portability and load triage
- PersistentVolumeClaim (PVC): a request for storage that outlives any one Pod. Read more: 10.4 Helm charts and the observability stack in Systems Engineering
- DaemonSet: a Kubernetes object that runs one Pod on every node, used for per-node agents such as log shippers and monitoring. Read more: Chapter 9: Cloud Native Architecture in Systems Engineering
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- Little’s law: , mean in-flight requests equal arrival rate times mean time in system. Read more: 20.4.6 Load tests and the deployment runbook
- startup probe: a probe that holds off liveness checks until a slow-starting container is up; for model servers it covers the cold start. Read more: 20.7.5 Adapter fleets and operations
- readiness probe / liveness probe: checks that, on failure, remove a Pod from its Service or restart its container, respectively. Read more: 10.1 Tracer deploy: images, a kind cluster, two Helm charts, and Jaeger in Systems Engineering
- Load balancer: a component that spreads traffic across instances of a service by round-robin, least connections, or consistent hashing, at layer 4 (TCP) or layer 7 (HTTP). Read more: Chapter 1: System Design in Systems Engineering
- TTFT (time to first token): time from a request’s arrival to its first generated token. Read more: 23.4 Chunked prefill (mixed prefill + decode batches)
- Graph capture: recording a device execution graph for later replay with supported shapes and buffers. Read more: 20.10 Runtime controls and inference flags
Learning objectives
- Trace immutable model artifacts into a ready serving replica.
Getting weights from Hugging Face onto the node
Section titled “Getting weights from Hugging Face onto the node”A replica cannot serve until its weights are in GPU memory, and on Kubernetes the dominant term is usually getting them onto the node. Model Loading gives cold start as roughly the checkpoint size divided by the slowest link, plus engine initialization. On a cluster there is a second cost: a scale-out event loads the same bytes into several pods at once, through a link they share.
The strategies, from worst to best for production:
| Strategy | How | Cold start (70 GB, FP8 70B) | Fails how |
|---|---|---|---|
| Download at pod start | hf download in an init container, into an emptyDir | Minutes, bounded by the Hub and egress | Hub rate limits and outages become your outages; every replica pays it |
| Bake into the image | COPY weights into the container image | Image pull: minutes for a 70 GB layer, and the registry must store it | Every weight change is a 70 GB image push |
| Shared volume | A Job downloads once into a ReadWriteMany PVC (NFS, Filestore, EFS, CephFS); pods mount it read-only | Volume bandwidth, shared by every pod loading at once | A scale-out storm divides the bandwidth |
| Object-store mirror plus streaming | Mirror the pinned revision to S3 or GCS; the engine streams tensors directly (--load-format runai_streamer) | 30 to 90 s at several GB/s | Needs a fast bucket in the same region |
| Node-local cache | A DaemonSet or an init container copies to local NVMe once per node; pods mount it with hostPath or a local PV | About 10 s at 7 GB/s | Node replacement re-pays the copy |
Work the scale-out storm for the shared volume. Five replicas start at once; the NFS server sustains 1.5 GB/s in aggregate; each must read 70 GB. The total is 350 GB, so the last replica is ready after s, plus a minute of engine initialization, compared with about 10 s from local NVMe. If the autoscaler fires because the queue is already growing, that difference is four minutes of SLO breach.
Whichever strategy you pick, four rules hold:
- Pin the revision. Download a 40-character commit sha, not
main. A replica that starts tomorrow must load the bytes you load-tested today. - Never contact the Hub from a serving pod. Set
HF_HUB_OFFLINE=1so that a missing file fails loudly at startup instead of triggering a download during a scale-out. - Keep the token in a Secret. Gated models such as Llama need an
HF_TOKENwith read access, mounted into the download Job only, not into the serving pods. - Download only what you serve. A repo may hold the same weights in several formats;
--includepatterns keep*.safetensors, the JSON files, and the tokenizer, and skiporiginal/and*.pth.
Here is the download Job for the shared-volume strategy. It runs once per model revision:
apiVersion: batch/v1kind: Jobmetadata: name: fetch-llama-3-1-70b-instructspec: backoffLimit: 3 template: spec: restartPolicy: OnFailure containers: - name: fetch image: python:3.12-slim command: ["bash", "-c"] args: - | pip install --no-cache-dir "huggingface_hub[hf_xet]" && hf download meta-llama/Llama-3.1-70B-Instruct \ --revision "$REVISION" \ --include "*.safetensors" "*.json" "tokenizer*" \ --local-dir "/models/llama-3.1-70b-instruct/$REVISION" env: - name: REVISION value: "<pinned 40-character commit sha>" - name: HF_TOKEN valueFrom: secretKeyRef: { name: hf-read-token, key: token } volumeMounts: - { name: models, mountPath: /models } volumes: - name: models persistentVolumeClaim: { claimName: model-store }The path includes the revision, so two revisions can coexist on the volume during a rollout and a rollback is a path change, not a re-download.
The Deployment
Section titled “The Deployment”With weights on a volume, the Deployment is short, and almost every field is there for a reason specific to model servers:
apiVersion: apps/v1kind: Deploymentmetadata: name: llama-70bspec: replicas: 5 strategy: type: RollingUpdate rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } selector: { matchLabels: { app: llama-70b } } template: metadata: labels: { app: llama-70b } spec: nodeSelector: nvidia.com/gpu.product: NVIDIA-H100-80GB-HBM3 tolerations: - { key: nvidia.com/gpu, operator: Exists, effect: NoSchedule } terminationGracePeriodSeconds: 120 containers: - name: vllm image: vllm/vllm-openai:v0.31.0 args: - --model=/models/llama-3.1-70b-instruct/<sha> - --served-model-name=llama-70b - --tensor-parallel-size=2 - --quantization=fp8 - --kv-cache-dtype=fp8 - --max-model-len=8192 - --max-num-seqs=160 - --max-num-batched-tokens=4096 - --enable-prefix-caching - --gpu-memory-utilization=0.90 - --port=8000 env: - { name: HF_HUB_OFFLINE, value: "1" } ports: - { name: http, containerPort: 8000 } resources: requests: { nvidia.com/gpu: 2, cpu: "12", memory: 128Gi } limits: { nvidia.com/gpu: 2, memory: 128Gi } startupProbe: httpGet: { path: /health, port: http } periodSeconds: 10 failureThreshold: 60 readinessProbe: httpGet: { path: /health, port: http } periodSeconds: 5 livenessProbe: httpGet: { path: /health, port: http } periodSeconds: 15 failureThreshold: 4 lifecycle: preStop: exec: { command: ["sleep", "15"] } volumeMounts: - { name: models, mountPath: /models, readOnly: true } - { name: dshm, mountPath: /dev/shm } volumes: - name: models persistentVolumeClaim: { claimName: model-store, readOnly: true } - name: dshm emptyDir: { medium: Memory, sizeLimit: 16Gi }Read it field by field, as the reasons are the lesson.
- The engine flags are the runbook’s output. Nothing here is chosen in the manifest; TP, precision,
max-model-len, andmax-num-seqsall came from the memory budget and Little’s law. - The startup probe covers the cold start. Ten-second periods with a failure threshold of 60 give the pod ten minutes to load weights and capture CUDA graphs before Kubernetes kills it. Without a startup probe, the liveness probe would start immediately, fail during loading, and restart the pod forever, never getting past the load. Set the budget from the cold-start math, about twice the measured worst case.
- Readiness gates traffic.
/healthreturns success only once the engine is serving. Until then the pod receives no requests from the Service. - The preStop sleep and the grace period drain streams. When a pod is deleted, it is removed from the Service’s endpoints at roughly the same time it receives SIGTERM. The 15-second sleep lets load balancers stop sending new requests first; the 120-second grace lets in-flight generations finish rather than be cut off mid-stream. That covers outputs of about 2,000 tokens; A request’s path through the cluster sizes it for longer ones.
memoryhas a limit;cpudoes not. A memory limit protects the node. A CPU limit throttles the tokenizer and scheduler under CFS quotas, which shows up as unexplained TTFT spikes./dev/shmis memory-backed. This is the shared-memory fix from the pod-shape table. Its size counts against the pod’s memory.
The Service in front of it is an ordinary ClusterIP on port 8000. Its round-robin load balancing is acceptable for one model without a large shared prefix; the routing section below says when it is not.
Review questions
Section titled “Review questions”-
Why should readiness wait beyond the point where the process starts?
Answer
Weights, device buffers, kernel warmup, and any required graph capture must be ready to serve the declared workload.