Scale a vLLM engine on actual inference demand: out when requests arrive, all the way down to zero pods when nobody's asking. KEDA does the scaling, reading Prometheus metrics.
Standalone: this project owns its VPC, EKS cluster, GPU nodes, GPU Operator and KEDA via
its own Terraform (terraform/) in its own HCP workspace (llm-autoscaling-keda). It shares
nothing with projects 1 or 4. values.yaml carries the same monitoring stack project 4 built,
because KEDA's triggers are Prometheus queries — no Prometheus, nothing to scale on.
Done when: the qwen-1p5b engine walks 0 → 1 → 2 → 0 on its own, driven by request rate and
queue depth, with no kubectl scale from me.
2× g6.xlarge (L4 24GB, ~$0.805/hr each), set by gpu_node_count in
terraform/variables.tf. Scale-to-zero needs no extra GPU; scaling out to two replicas uses
the card freed up by parking the 7b engine.
| Trigger | Metric | What it's for |
|---|---|---|
| Router incoming rate | vllm:num_incoming_requests_total{model="…1.5B…"} |
Scraped from the router, so it still reports when the engine has zero pods. This is what wakes it 0 → 1. |
| Engine queue depth | vllm:num_requests_waiting{model_name="…1.5B…"} |
The classic backpressure signal. Drives 1 → 2. Only exists once a pod is running. |
Here's the trap. Queue depth is the right metric for inference load, so it's tempting to use
only that. But when the engine scales to zero its pod disappears, and so does its /metrics
endpoint. A queue-depth-only scaler would have nothing to read and could never wake back up. The
router keeps counting requests whether or not any engine exists, which is what makes 0 → 1
possible.
KEDA takes whichever of the two asks for more replicas.
Prereqs: aws CLI configured, and an HCP Terraform workspace named llm-autoscaling-keda in
the Shikha_Projects org with Execution Mode = Local.
# 1. Infrastructure: VPC, EKS, system node, 2x GPU node, NVIDIA GPU Operator, and KEDA.
# KEDA is installed here, not by hand — it's a platform component like the GPU Operator,
# and it's what creates the ScaledObject CRD used in step 3.
cd terraform && terraform init && terraform apply
terraform output -raw configure_kubectl | bash
cd ..
# 1b. Then the vLLM stack WITH Prometheus — KEDA scales on Prometheus queries, so the
# monitoring stack is a hard dependency, not an optional extra.
# --repo resolves the chart directly — no `helm repo add`, no local cache to drift.
helm install vllm vllm-stack \
--repo https://vllm-project.github.io/production-stack -f values.yaml
# 2. Free a GPU for the second replica by parking the 7b engine
kubectl scale deploy/vllm-qwen-7b-awq-deployment-vllm --replicas=0
# 3. Apply the autoscaler
kubectl apply -f k8s/keda-scaledobject.yaml
# 4. KEDA creates an HPA under the hood. Both should exist.
kubectl get scaledobject,hpaThat last point is worth internalising: KEDA doesn't replace the HPA, it writes one. KEDA's job is turning external metrics (Prometheus, Kafka, SQS) into something the HPA can consume, plus the 0 ↔ 1 transition that the HPA can't do by itself.
# terminal 1 — replicas, live
kubectl get pods -l app.kubernetes.io/name=vllm-qwen-1p5b -w
# Let it idle ~2 min and it should hit 0. Then drive load:
DURATION=180 RPS=8 MODEL="Qwen/Qwen2.5-1.5B-Instruct" bash scripts/generate-load.sh
# Expect 0 -> 1 (router rate wakes it) -> 2 (rate keeps climbing) -> 0 after cooldown.
# What KEDA decided and why:
kubectl describe scaledobject vllm-qwen-1p5b | sed -n '/Events/,$p'
kubectl get hpa keda-hpa-vllm-qwen-1p5b -o wideUnder load, activated from zero and scaled out to two:
$ kubectl get deploy
vllm-qwen-1p5b-deployment-vllm 0/2 2 0 # 2 desired, pods still booting (cold start)
vllm-qwen-7b-awq-deployment-vllm 0/0 0 0 # parked to free a GPU
$ kubectl describe scaledobject vllm-qwen-1p5b | sed -n '/Events/,$p'
Normal KEDAScaleTargetActivated 72s keda-operator Scaled ... from 0 to 1, triggered by s0-prometheus
$ kubectl get hpa keda-hpa-vllm-qwen-1p5b -o wide
TARGETS MINPODS MAXPODS REPLICAS
3867m/2 (avg), 0/3 (avg) 1 2 2
# router rate 3.87 req/s against a target of 2 per replica -> 2 pods
# queue depth 0/3 -> no backlog
After the load stopped, back to zero:
$ kubectl describe scaledobject vllm-qwen-1p5b | sed -n '/Events/,$p'
Normal KEDAScaleTargetActivated 6m59s keda-operator Scaled ... from 0 to 1, triggered by s0-prometheus
Normal KEDAScaleTargetDeactivated 104s keda-operator Deactivated ... from 1 to 0
$ kubectl get hpa keda-hpa-vllm-qwen-1p5b -o wide
TARGETS MINPODS MAXPODS REPLICAS
<unknown>/2 (avg), <unknown>/3 (avg) 1 2 0
$ kubectl get deploy
vllm-qwen-1p5b-deployment-vllm 0/0 0 0 # scaled to zero, GPU freed
Reading the run: the full 0 → 2 → 0 loop happened with no manual scaling. Activation came from
the router rate trigger (s0-prometheus), the one that survives at zero replicas. Scale-out
to two was driven by request rate (3.87 against a target of 2), while queue depth stayed at
zero, meaning two replicas absorbed the traffic without ever building a backlog.
Both odd-looking bits are expected, not faults. <unknown> targets appear because engine metrics
don't exist at zero replicas, which is the whole reason reactivation uses the router metric. The
0/2 window is cold start: pods are counted as desired before the model has finished loading.
# --- install (one-time) ---
cd terraform && terraform apply && cd .. # cluster + GPU Operator + KEDA
helm install vllm vllm-stack --repo https://vllm-project.github.io/production-stack -f values.yaml
# --- deploy ---
kubectl scale deploy/vllm-qwen-7b-awq-deployment-vllm --replicas=0 # park 7b, free a GPU
kubectl apply -f k8s/keda-scaledobject.yaml
# --- inspect ---
kubectl get scaledobject,hpa # KEDA object + generated HPA
kubectl get deploy vllm-qwen-1p5b-deployment-vllm # live replica count
kubectl describe scaledobject vllm-qwen-1p5b | sed -n '/Events/,$p' # scale up/down events
kubectl get hpa keda-hpa-vllm-qwen-1p5b -o wide # metric value vs target
# --- drive load ---
DURATION=180 RPS=8 MODEL="Qwen/Qwen2.5-1.5B-Instruct" bash scripts/generate-load.sh
# --- teardown ---
kubectl delete -f k8s/keda-scaledobject.yaml
kubectl scale deploy/vllm-qwen-7b-awq-deployment-vllm --replicas=1 # restore 7bthresholdis the target metric value per replica. The HPA divides the total by it, so a lower threshold scales out sooner.activationThresholdis a different thing: it's the 0 → 1 wake level, and only applies to triggers that still report at zero.cooldownPeriodis how long it stays idle before dropping to zero.pollingIntervalis how often KEDA checks.- Cold start is the real cost of scale-to-zero. The first requests after an idle period hit
the router while the engine is still loading, and they may 5xx or retry. Two production
answers: keep
minReplicaCount: 1for latency-critical models and give up the savings, or run the KEDA HTTP add-on, a proxy that holds the request open until the pod is ready. - Node autoscaling is a separate problem. Scaling past the GPUs you already have needs
Cluster Autoscaler or Karpenter to add a node. Here
maxReplicaCountis deliberately capped to the cards on hand, so KEDA never asks for capacity that can't arrive.
# Just stop autoscaling, keep the cluster
kubectl delete -f k8s/keda-scaledobject.yaml
kubectl scale deploy/vllm-qwen-7b-awq-deployment-vllm --replicas=1 # restore the 7b engine
# Park the GPUs between sessions (~$1.61/hr of the ~$1.85/hr)
cd terraform && terraform output -raw scale_gpus_to_zero | bash
# Done for good
helm uninstall vllm
cd terraform && terraform destroy # also removes KEDA, cluster, VPC, NATKEDA is no longer a helm uninstall — Terraform owns it, so terraform destroy takes it.
Uninstall the vLLM release before destroying, or the kube-prometheus-stack CRDs and any
LoadBalancer-held ENIs can stall the VPC delete.