Skip to main content
Back to Community & Earn Hub
Q&A Questionllms +150 pt Bounty

Kubernetes Horizontal Pod Autoscaler (HPA) for vLLM Inference: Why CPU/GPU utilization metrics fail and how to autoscale on vllm:num_requests_waiting?

@tanvi_kulkarni4 days ago 1498 views

We deploy vLLM inference replicas on Kubernetes (EKS/GKE) behind an HPA.

Why Standard HPA Metrics Fail

  1. CPU Utilization: vLLM's Python/C++ engine hovers around 15–25% CPU regardless of whether 1 or 50 concurrent requests are running, so CPU HPA never scales up.
  2. DCGM DCGM_FI_DEV_GPU_UTIL: Even a single active decode request drives GPU SM utilization to 95–99% during memory-bound token generation! That causes GPU-util HPA to scale up to max replicas unnecessarily on 1 user, or oscillate wildly.

We want HPA to scale strictly when requests start queuing (vllm:num_requests_waiting) or KV-cache approaches saturation (vllm:gpu_cache_usage_perc).

What is the exact Prometheus ServiceMonitor + prometheus-adapter custom metric rule and HPA manifest to make vLLM autoscaling smooth without scale-down thrashing?

1 Answers

Community Answers

@rohan_mehta Accepted Answer4 days ago

You hit the exact reason GPU SM utilization is useless for LLM autoscaling: decode is memory-bandwidth bound, so 1 concurrent sequence saturates SM cycles just like 32 sequences.

The production standard for vLLM Kubernetes HPA is exposing vLLM's built-in /metrics endpoint via Prometheus Adapter and scaling on vllm:num_requests_waiting (queue depth) + vllm:gpu_cache_usage_perc (KV-cache pressure).


1. Configure prometheus-adapter Custom Metric Rules

Map vLLM's native Prometheus gauges to Kubernetes custom.metrics.k8s.io/v1beta1:

yaml
# prometheus-adapter values.yaml
rules:
  custom:
    - seriesQuery: 'vllm:num_requests_waiting{namespace!="",pod!=""}'
      resources:
        overrides:
          namespace: {resource: "namespace"}
          pod: {resource: "pod"}
      name:
        matches: "^vllm:num_requests_waiting$"
        as: "vllm_requests_waiting"
      metricsQuery: 'avg_over_time(<<.Series>>{<<.LabelMatchers>>}[1m])'

    - seriesQuery: 'vllm:gpu_cache_usage_perc{namespace!="",pod!=""}'
      resources:
        overrides:
          namespace: {resource: "namespace"}
          pod: {resource: "pod"}
      name:
        matches: "^vllm:gpu_cache_usage_perc$"
        as: "vllm_gpu_cache_usage_perc"
      metricsQuery: 'avg_over_time(<<.Series>>{<<.LabelMatchers>>}[1m])'

(Using avg_over_time(...[1m]) prevents micro-bursts from triggering premature GPU pod spin-ups.)


2. HPA Manifest with Asymmetric Scale-Down Stabilization

Because vLLM pods take 45–90 seconds to load 70B weights into VRAM, always set a generous stabilizationWindowSeconds: 600 on scaleDown so you don't evict warm pods right before the next request wave:

yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: vllm-llama-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: vllm-llama-70b
  minReplicas: 2
  maxReplicas: 10
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 30
      policies:
        - type: Pods
          value: 2
          periodSeconds: 60
    scaleDown:
      stabilizationWindowSeconds: 600 # Keep warm GPU weights for 10 mins
      policies:
        - type: Pods
          value: 1
          periodSeconds: 180
  metrics:
    - type: Pods
      pods:
        metric:
          name: vllm_requests_waiting
        target:
          type: AverageValue
          averageValue: "3" # Scale up when >3 requests wait per pod
    - type: Pods
      pods:
        metric:
          name: vllm_gpu_cache_usage_perc
        target:
          type: AverageValue
          averageValue: "750m" # 0.75 (75% KV-cache saturation)

With vllm_requests_waiting + vllm_gpu_cache_usage_perc and a 10-minute scale-down window, your cluster scales cleanly ahead of KV-cache exhaustion with zero oscillation.

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.