KEDA for LLM autoscaling
Gets the replicas of an LLM Deployment (vLLM, SGLang, TGI, any OpenAI-compatible server) to follow real load: queue depth,
KV-cache pressure, a work queue or GPU metrics, with a controlled scale-down and, if you accept the cold start, scale to
zero. Verified against KEDA v2.21.0 and HTTP add-on v0.16.0 (2026-10-11).
Scope: KEDA used for LLM autoscaling only: Prometheus, metrics-api and queue triggers on model servers and workers. Not
a general KEDA manual (other scalers: keda.sh/docs/2.21/scalers). KServe plus KEDA wiring is vllm-kserve-keda.
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Never print tokens or Secret values.
kubectl get crd | grep -E 'keda.sh' # scaledobjects, triggerauthentications, ...
kubectl get deploy,pods -n keda 2>/dev/null # operator, metrics-apiserver, admission webhooks
helm list -A | grep -i keda # chart and app version
kubectl get apiservice v1beta1.external.metrics.k8s.io # must be Available; only ONE provider per cluster
kubectl get scaledobject,hpa -A # existing scaling objects (HPA name keda-hpa-<so>)
kubectl get svc -A | grep -Ei 'prometheus|thanos|victoria'
kubectl get deploy -A -o wide | grep -Ei 'vllm|sglang|tgi|llm'
kubectl get pods -A -o name | grep -i dcgm # GPU metrics source (skill dcgm-exporter)
Decision flow
- No KEDA ->
references/install.md (Helm, pinned, Prometheus metrics on). Metrics-server conflict check first.
- Pick the signal (
references/llm-triggers.md): sum of vllm:num_requests_waiting is the primary trigger;
vllm:kv_cache_usage_perc as a guard; queue length for batch or async workers (RabbitMQ, Redis, SQS, NATS).
Never GPU utilization alone: it sits near 100% at any load.
- Write the ScaledObject from
templates/scaledobject-vllm.yaml. Keep minReplicaCount at 1 or more unless
you accept a cold start (references/scale-to-zero.md).
- Prometheus needs auth or is multi-tenant ->
references/authentication.md and templates/triggerauth-prometheus.yaml.
- Scale to zero wanted -> the vLLM series vanish with the last pod, so the query must come from something that
survives (gateway, router or HTTP add-on):
references/scale-to-zero.md.
- Tune
pollingInterval, HPA behavior, fallback, thresholds against a load test:
references/scaledobject-tuning.md.
- Already on a stack? KServe ->
vllm-kserve-keda. Ray Serve -> do not add KEDA to its workers
(references/combos/ray-serve.md). llm-d or GAIE -> references/combos/gaie-epp.md.
- Upgrade ->
references/updating.md. Broken -> references/troubleshooting.md.
Quick start (vLLM Deployment, Prometheus scraping it)
helm repo add kedacore https://kedacore.github.io/charts && helm repo update
helm install keda kedacore/keda --namespace keda --create-namespace --version 2.21.0 # needs approval
kubectl apply -f templates/scaledobject-vllm.yaml # after setting names, namespace, serverAddress
kubectl get scaledobject -n <ns> # READY True, ACTIVE True when there is load
kubectl get hpa -n <ns> # keda-hpa-<name> shows the metric and target
Rules
- Ask before changing the system. Helm releases, CRDs, ScaledObjects, annotations and scale changes need approval and an
undo path:
kubectl delete scaledobject leaves replicas where they are unless
advanced.restoreToOriginalReplicaCount: true.
- Secrets never touch output. Prometheus tokens and queue URLs go in Secrets, referenced by
TriggerAuthentication
(secretTargetRef); create Secrets from 0600 files.
- One scaler per workload. Never put a second HPA, or an autoscaling operator such as Ray Serve's, on the same target.
- Do not hardcode prices or GPU counts in advice. Thresholds come from a load test on the real model and GPU.
- Verify upstream. Fields and defaults come from the 2.21 docs, checked on the writing date.
Facts that surprise people (KEDA 2.21.0)
- A ScaledObject creates an HPA named
keda-hpa-<name>. KEDA owns 0<->1 (activation); the HPA owns 1<->N.
- Defaults:
pollingInterval 30 s, cooldownPeriod 300 s (applies only to scaling to 0), minReplicaCount 0,
maxReplicaCount 100, initialCooldownPeriod 0, trigger metricType AverageValue.
- Prometheus trigger
ignoreNullValues defaults to true: an empty result means 0, so a vanished series scales
down quietly instead of erroring. Set "false" to surface a lost scrape target.
- With
AverageValue the metric is divided by current replicas, so threshold is per-replica: replicas =
ceil(sum / threshold). Query a sum(...), not an avg(...).
- Activation is strict "greater than":
activationThreshold: 0 activates at 1 or more. If minReplicaCount >= 1 the
activation value is ignored.
- If
minReplicaCount > 0 and none of idleReplicaCount, useCachedMetrics or scalingModifiers is set, KEDA stops
polling and the HPA drives everything.
- 2.21 enforces explicit audiences for bound service account tokens (CVE-2026-77524): read
references/authentication.md before upgrading from 2.20 if you use boundServiceAccountToken or Vault Kubernetes auth.
- KEDA 2.21 is tested with Kubernetes 1.34-1.36. The HTTP add-on is beta (v0.16.0,
InterceptorRoute).
Workflows
Autoscale a vLLM Deployment on queue depth
Add a safety net and a scale-down policy
Debug a stuck ScaledObject
Reference index
references/install.md: Helm, pinned versions, metrics on, CRDs, uninstall, compatibility.
references/llm-triggers.md: vLLM, DCGM, queue and metrics-api triggers with queries and thresholds.
references/scaledobject-tuning.md: spec fields that matter, HPA behavior, fallback, pause, caching, modifiers.
references/scale-to-zero.md: activation, cold start, what survives zero pods, HTTP add-on.
references/authentication.md: TriggerAuthentication, secrets, bearer/basic/TLS, 2.21 token audiences.
references/updating.md: KEDA upgrades and breaking changes 2.20 -> 2.21.
references/troubleshooting.md: symptom to cause to fix.
references/combos/vllm-pods.md, references/combos/gpu-operator-dcgm.md, references/combos/gaie-epp.md,
references/combos/ray-serve.md: stack-specific wiring.
templates/: scaledobject-vllm.yaml, scaledobject-queue-worker.yaml, triggerauth-prometheus.yaml, values-keda.yaml.
Companion skills
vllm-kserve-keda: KServe InferenceService with KEDA. Install: npx skills add ScaleDockHQ/llm-skills --skill vllm-kserve-keda.
vllm: engine flags and metrics. Install: npx skills add ScaleDockHQ/llm-skills --skill vllm.
nvidia-gpu-operator: GPU nodes and DCGM. Install: npx skills add ScaleDockHQ/llm-skills --skill nvidia-gpu-operator.
dcgm-exporter: GPU metrics. Install: npx skills add ScaleDockHQ/llm-skills --skill dcgm-exporter.
gateway-api-inference-extension: model-aware routing. Install: npx skills add ScaleDockHQ/llm-skills --skill gateway-api-inference-extension.
ray-serve: Ray's own autoscaling. Install: npx skills add ScaleDockHQ/llm-skills --skill ray-serve.
prometheus-grafana-llm: scraping and dashboards. Install: npx skills add ScaleDockHQ/llm-skills --skill prometheus-grafana-llm.
1---2name: keda3description: Autoscale LLM serving pods on Kubernetes with KEDA (ScaledObject, TriggerAuthentication, Prometheus scaler on vllm:num_requests_waiting, KV-cache or DCGM metrics, queue scalers, scale to zero, HTTP add-on). Use for keda, ScaledObject, scale vLLM replicas on queue depth, scale to zero, activationThreshold, cooldownPeriod, keda-hpa, ScalingActive false or flapping. Not for Ray Serve replicas (ray-serve), the KServe wiring (vllm-kserve-keda) or routing (llm-d).4license: MIT5compatibility: Kubernetes 1.34-1.36 for KEDA 2.21 with Prometheus scraping the model servers, kubectl, helm, bash, curl and jq. Helm installs, CRDs, ScaledObjects and scale changes need the user's explicit approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/keda8 author: ScaleDockHQ9 version: "0.1.0"10---1112# KEDA for LLM autoscaling1314Gets the replicas of an LLM Deployment (vLLM, SGLang, TGI, any OpenAI-compatible server) to follow real load: queue depth,15KV-cache pressure, a work queue or GPU metrics, with a controlled scale-down and, if you accept the cold start, scale to16zero. Verified against KEDA v2.21.0 and HTTP add-on v0.16.0 (2026-10-11).1718**Scope:** KEDA used for LLM autoscaling only: Prometheus, metrics-api and queue triggers on model servers and workers. Not19a general KEDA manual (other scalers: keda.sh/docs/2.21/scalers). KServe plus KEDA wiring is `vllm-kserve-keda`.2021Work through the steps in order. Load a reference only when a step names it.2223## Discover first2425Read-only. Never print tokens or Secret values.2627```bash28kubectl get crd | grep -E 'keda.sh' # scaledobjects, triggerauthentications, ...29kubectl get deploy,pods -n keda 2>/dev/null # operator, metrics-apiserver, admission webhooks30helm list -A | grep -i keda # chart and app version31kubectl get apiservice v1beta1.external.metrics.k8s.io # must be Available; only ONE provider per cluster32kubectl get scaledobject,hpa -A # existing scaling objects (HPA name keda-hpa-<so>)33kubectl get svc -A | grep -Ei 'prometheus|thanos|victoria'34kubectl get deploy -A -o wide | grep -Ei 'vllm|sglang|tgi|llm'35kubectl get pods -A -o name | grep -i dcgm # GPU metrics source (skill dcgm-exporter)36```3738## Decision flow39401. **No KEDA** -> `references/install.md` (Helm, pinned, Prometheus metrics on). Metrics-server conflict check first.412. **Pick the signal** (`references/llm-triggers.md`): sum of `vllm:num_requests_waiting` is the primary trigger;42 `vllm:kv_cache_usage_perc` as a guard; queue length for batch or async workers (RabbitMQ, Redis, SQS, NATS).43 Never GPU utilization alone: it sits near 100% at any load.443. **Write the ScaledObject** from `templates/scaledobject-vllm.yaml`. Keep `minReplicaCount` at 1 or more unless45 you accept a cold start (`references/scale-to-zero.md`).464. **Prometheus needs auth or is multi-tenant** -> `references/authentication.md` and `templates/triggerauth-prometheus.yaml`.475. **Scale to zero wanted** -> the vLLM series vanish with the last pod, so the query must come from something that48 survives (gateway, router or HTTP add-on): `references/scale-to-zero.md`.496. **Tune** `pollingInterval`, HPA `behavior`, `fallback`, thresholds against a load test:50 `references/scaledobject-tuning.md`.517. **Already on a stack?** KServe -> `vllm-kserve-keda`. Ray Serve -> do not add KEDA to its workers52 (`references/combos/ray-serve.md`). llm-d or GAIE -> `references/combos/gaie-epp.md`.538. **Upgrade** -> `references/updating.md`. **Broken** -> `references/troubleshooting.md`.5455## Quick start (vLLM Deployment, Prometheus scraping it)5657```bash58helm repo add kedacore https://kedacore.github.io/charts && helm repo update59helm install keda kedacore/keda --namespace keda --create-namespace --version 2.21.0 # needs approval60kubectl apply -f templates/scaledobject-vllm.yaml # after setting names, namespace, serverAddress61kubectl get scaledobject -n <ns> # READY True, ACTIVE True when there is load62kubectl get hpa -n <ns> # keda-hpa-<name> shows the metric and target63```6465## Rules6667- **Ask before changing the system.** Helm releases, CRDs, ScaledObjects, annotations and scale changes need approval and an68 undo path: `kubectl delete scaledobject` leaves replicas where they are unless69 `advanced.restoreToOriginalReplicaCount: true`.70- **Secrets never touch output.** Prometheus tokens and queue URLs go in Secrets, referenced by `TriggerAuthentication`71 (`secretTargetRef`); create Secrets from `0600` files.72- **One scaler per workload.** Never put a second HPA, or an autoscaling operator such as Ray Serve's, on the same target.73- **Do not hardcode prices or GPU counts in advice.** Thresholds come from a load test on the real model and GPU.74- **Verify upstream.** Fields and defaults come from the 2.21 docs, checked on the writing date.7576## Facts that surprise people (KEDA 2.21.0)7778- A ScaledObject creates an HPA named `keda-hpa-<name>`. KEDA owns 0<->1 (activation); the HPA owns 1<->N.79- Defaults: `pollingInterval` 30 s, `cooldownPeriod` 300 s (applies only to scaling to 0), `minReplicaCount` 0,80 `maxReplicaCount` 100, `initialCooldownPeriod` 0, trigger `metricType` `AverageValue`.81- Prometheus trigger `ignoreNullValues` defaults to `true`: an empty result means 0, so a vanished series scales82 down quietly instead of erroring. Set `"false"` to surface a lost scrape target.83- With `AverageValue` the metric is divided by current replicas, so `threshold` is per-replica: replicas =84 ceil(sum / threshold). Query a `sum(...)`, not an `avg(...)`.85- Activation is strict "greater than": `activationThreshold: 0` activates at 1 or more. If `minReplicaCount >= 1` the86 activation value is ignored.87- If `minReplicaCount > 0` and none of `idleReplicaCount`, `useCachedMetrics` or `scalingModifiers` is set, KEDA stops88 polling and the HPA drives everything.89- 2.21 enforces explicit audiences for bound service account tokens (CVE-2026-77524): read90 `references/authentication.md` before upgrading from 2.20 if you use `boundServiceAccountToken` or Vault Kubernetes auth.91- KEDA 2.21 is tested with Kubernetes 1.34-1.36. The HTTP add-on is beta (v0.16.0, `InterceptorRoute`).9293## Workflows9495### Autoscale a vLLM Deployment on queue depth9697- [ ] Confirm Prometheus scrapes the pods: query `vllm:num_requests_waiting` in Prometheus; note labels.98- [ ] Install KEDA if missing (`references/install.md`).99- [ ] Adapt `templates/scaledobject-vllm.yaml` (label selector, threshold, min/max, HPA behavior).100- [ ] Load test; watch `kubectl get hpa -w` and the pending/Ready replica timeline; tune101 (`references/scaledobject-tuning.md`).102103### Add a safety net and a scale-down policy104105- [ ] `fallback` with `behavior: currentReplicasIfHigher`, a stabilization window of 10+ minutes for scale-down.106- [ ] Alert on `keda_scaler_detail_errors_total` and on the HPA at `maxReplicas` (`references/scaledobject-tuning.md`).107108### Debug a stuck ScaledObject109110- [ ] `kubectl describe scaledobject`, KEDA operator logs, then `references/troubleshooting.md`.111112## Reference index113114- `references/install.md`: Helm, pinned versions, metrics on, CRDs, uninstall, compatibility.115- `references/llm-triggers.md`: vLLM, DCGM, queue and metrics-api triggers with queries and thresholds.116- `references/scaledobject-tuning.md`: spec fields that matter, HPA behavior, fallback, pause, caching, modifiers.117- `references/scale-to-zero.md`: activation, cold start, what survives zero pods, HTTP add-on.118- `references/authentication.md`: `TriggerAuthentication`, secrets, bearer/basic/TLS, 2.21 token audiences.119- `references/updating.md`: KEDA upgrades and breaking changes 2.20 -> 2.21.120- `references/troubleshooting.md`: symptom to cause to fix.121- `references/combos/vllm-pods.md`, `references/combos/gpu-operator-dcgm.md`, `references/combos/gaie-epp.md`,122 `references/combos/ray-serve.md`: stack-specific wiring.123- `templates/`: `scaledobject-vllm.yaml`, `scaledobject-queue-worker.yaml`, `triggerauth-prometheus.yaml`, `values-keda.yaml`.124125## Companion skills126127- `vllm-kserve-keda`: KServe InferenceService with KEDA. Install: `npx skills add ScaleDockHQ/llm-skills --skill vllm-kserve-keda`.128- `vllm`: engine flags and metrics. Install: `npx skills add ScaleDockHQ/llm-skills --skill vllm`.129- `nvidia-gpu-operator`: GPU nodes and DCGM. Install: `npx skills add ScaleDockHQ/llm-skills --skill nvidia-gpu-operator`.130- `dcgm-exporter`: GPU metrics. Install: `npx skills add ScaleDockHQ/llm-skills --skill dcgm-exporter`.131- `gateway-api-inference-extension`: model-aware routing. Install: `npx skills add ScaleDockHQ/llm-skills --skill gateway-api-inference-extension`.132- `ray-serve`: Ray's own autoscaling. Install: `npx skills add ScaleDockHQ/llm-skills --skill ray-serve`.133- `prometheus-grafana-llm`: scraping and dashboards. Install: `npx skills add ScaleDockHQ/llm-skills --skill prometheus-grafana-llm`.