Skip to main content
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
Kubernetes clusterClientsChat requestsGateway · routerSends to Ready replicasReplica 1vLLM · 1 GPUReplica 2vLLM · 1 GPUReplica 3New · loadingPrometheusScrapes /metricsKEDA / AdapterMetric for the HPAHPADesired replicasGPU node poolFree GPUs?Node autoscalere.g. KarpenterRequestsStreamStream
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​

SignalGood for LLMs?Why
CPU utilizationNoThe engine mostly waits on the GPU, so CPU stays low even when users queue
GPU utilization (e.g. DCGM_FI_DEV_GPU_UTIL)NoIt measures time a kernel was running, which is near 100% once any request decodes
Waiting requests (vllm:num_requests_waiting)Yes, main signalRises as soon as replicas cannot take more requests into the batch
KV cache use (vllm:kv_cache_usage_perc)Yes, early warningNear 100% means new requests will wait or running ones get preempted
TTFT p95 (vllm:time_to_first_token_seconds)For SLOs and alertsWhat users feel, but it moves only after they already wait
Requests per secondWeakPrompt 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

  1. An HPA on GPU utilization scaled an LLM Deployment out and never scaled it back in. Why?
  2. kubectl describe hpa shows the waiting-requests metric as unknown. Where is the problem?
  3. When a replica is removed during scale-in, some users see their answer stop mid-sentence. What fixes this?

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