AI on Kubernetes · GPU/NPULesson 16 of 20
Autoscaling LLM Inference
The HPA from Scaling with Load works well for web Pods on CPU. An LLM replica is different: its GPU looks busy all the time, a new replica takes minutes to start, and one shut down too early cuts off answers mid-stream. Follow one traffic spike and see which signals to scale on and where the delays come from.
GPU util97%
Waiting requests0
KV cache use40%
TTFT p950.6 s
Replicas2
RequestWatchAppears in a later step
What you will learn
- Why GPU and CPU utilization are poor scaling signals for LLMs
- Waiting requests, KV cache use and TTFT from the engine
- How the metric reaches the HPA through KEDA or an adapter
- GPU node provisioning and cold start delay every scale-out
- Scale-down must let running streams finish
- What scale-to-zero saves and what it costs
Which signal to scale on
| Signal | Good for LLMs? | Why |
|---|---|---|
| CPU utilization | No | The engine mostly waits on the GPU, so CPU stays low even when users queue |
GPU utilization (e.g. DCGM_FI_DEV_GPU_UTIL) | No | It measures time a kernel was running, which is near 100% once any request decodes |
Waiting requests (vllm:num_requests_waiting) | Yes, main signal | Rises as soon as replicas cannot take more requests into the batch |
KV cache use (vllm:kv_cache_usage_perc) | Yes, early warning | Near 100% means new requests will wait or running ones get preempted |
TTFT p95 (vllm:time_to_first_token_seconds) | For SLOs and alerts | What users feel, but it moves only after they already wait |
| Requests per second | Weak | Prompt and answer lengths vary a lot, so the same rate can be light or heavy load |
Try it yourself
kubectl port-forward deploy/llm 8000:8000 &
curl -s localhost:8000/metrics | grep -E '^vllm:(num_requests_waiting|num_requests_running|kv_cache_usage_perc)' # The engine's own load
kubectl get hpa -w # TARGETS (current/target) and REPLICAS as load changes
kubectl describe hpa keda-hpa-llm # Metric value, events, why it did or did not scale
kubectl get scaledobject # KEDA: READY and ACTIVE
kubectl get pods -l app=llm -w # Pending (no GPU node) → Running → Ready (model loaded)
A KEDA ScaledObject that scales on waiting requests:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: llm
spec:
scaleTargetRef:
name: llm # The vLLM Deployment
minReplicaCount: 1 # 0 allows scale to zero, with a cold start on wake
maxReplicaCount: 8
advanced:
horizontalPodAutoscalerConfig:
behavior:
scaleDown:
stabilizationWindowSeconds: 600 # Scale in slowly
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus.monitoring:9090
query: sum(vllm:num_requests_waiting{model_name="chat"})
threshold: "5" # Target waiting requests per replica
Check yourself
Further reading: vLLM metrics · KEDA Prometheus scaler · Horizontal Pod Autoscaling · Karpenter · Scaling with Load (HPA) · Until a Model First Starts (Cold Start) · Which Replica Gets the Request · Graceful shutdown