Skip to content

[Feat] Support KEDA Auto Scaling in Production Stack Operator - #903

Merged
ruizhang0101 merged 8 commits into
vllm-project:mainfrom
aeon-x:support_autoscaling_in_operator
Apr 14, 2026
Merged

ruizhang0101 merged 8 commits into
vllm-project:mainfrom
aeon-x:support_autoscaling_in_operator

Conversation

@aeon-x

@aeon-x aeon-x commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add built-in KEDA autoscaling support so that the operator automatically creates a ScaledObject for each VLLMRuntime CR when autoscaling is enabled. This enables per-deployment autoscaling (including scale-to-zero) based on Prometheus metrics without manually creating ScaledObjects.

Key design decision

KEDA targets the VLLMRuntime CR via its scale subresource (not the Deployment directly), so the CR remains the single source of truth for replicas. This eliminates the operator/KEDA replica conflict: KEDA updates CR replicas → operator reconciles → Deployment updated.

Changes

CRD (api/v1alpha1/vllmruntime_types.go)

  • Added scale subresource marker (specpath, statuspath, selectorpath) to VLLMRuntime
  • Added Replicas and Selector fields to VLLMRuntimeStatus (required by HPA for AverageValue metric division)
  • Added AutoscalingConfig struct with configurable thresholds, timing, and HPA stabilization windows

Controller (internal/controller/vllmruntime_controller.go)

  • Added reconcileScaledObject() — creates/updates KEDA ScaledObject via server-side apply, gated by AutoscalingConfig.Enabled
  • Updated updateStatus() to set status.replicas and status.selector from the Deployment
  • Added RBAC markers for keda.sh/scaledobjects and vllmruntimes/scale

Prometheus triggers (4 total)

  1. Router keepalive (metricType: Value) — controls 0↔1 scaling, always available even with 0 pods
  2. Concurrent requests (AverageValue) — sum(vllm:num_requests_running), threshold: 5/pod
  3. Generation tokens/s (AverageValue) — sum(rate(vllm:generation_tokens_total[1m])), threshold: 100/pod
  4. Prompt tokens/s (AverageValue) — sum(rate(vllm:prompt_tokens_total[1m])), threshold: 100/pod

Generated manifests

  • Regenerated CRD with scale subresource and autoscalingConfig schema
  • Regenerated RBAC with keda.sh and /scale permissions

Example CR

apiVersion: production-stack.vllm.ai/v1alpha1
kind: VLLMRuntime
spec:
  autoscalingConfig:
    enabled: true
    minReplicas: 0
    maxReplicas: 4
    requestsRunningThreshold: "5"
    generationTokensThreshold: "100"
    promptTokensThreshold: "100"
    pollingInterval: 15
    cooldownPeriod: 1800
    scaleUpStabilizationWindowSeconds: 0
    scaleDownStabilizationWindowSeconds: 300

Signed-off-by: aeon-x <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces KEDA-based autoscaling for the VLLMRuntime operator by adding an AutoscalingConfig to the API and implementing the reconciliation logic for ScaledObject resources. Key feedback includes ensuring that ScaledObject resources are deleted when autoscaling is disabled and correcting Prometheus triggers to use AverageValue for accurate per-pod scaling. Additionally, the status.replicas field should reflect actual running replicas for HPA consistency, the MaxReplicas field requires validation or a default value, and the hardcoded Prometheus server address should be made configurable.

Signed-off-by: aeon-x <[email protected]>

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
Could you add some test and a tutorial/example yaml file?

"metadata": map[string]string{
"serverAddress": prometheusAddr,
"metricName": "vllm_incoming_keepalive",
"query": fmt.Sprintf(`sum(rate(vllm:num_incoming_requests_total{namespace="%s", model="%s"}[1m]) > bool 0)`, vllmRuntime.Namespace, servedModelName),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use job label as well to align with the other triggers?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keepalive trigger uses namespace + model labels because it comes from the router, not the vLLM pod. The router is always running (even when pods are scaled to zero), which is why it can trigger scale-from-zero.

The other triggers use job label because they come from the vLLM pod metrics — those are only available when pods are running.

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :))

@ruizhang0101
ruizhang0101 merged commit 7b39611 into vllm-project:main Apr 14, 2026
7 checks passed
shernshiou pushed a commit to shernshiou/production-stack that referenced this pull request Apr 15, 2026
…roject#903)

* init

Signed-off-by: aeon-x <[email protected]>

* update proto

Signed-off-by: aeon-x <[email protected]>

* fix review comments

Signed-off-by: aeon-x <[email protected]>

* fix review comments for autoscaling

Signed-off-by: aeon-x <[email protected]>

* fix lint

Signed-off-by: aeon-x <[email protected]>

---------

Signed-off-by: aeon-x <[email protected]>
Co-authored-by: Rui Zhang <[email protected]>
ikaadil pushed a commit to ikaadil/production-stack that referenced this pull request May 2, 2026
…roject#903)

* init

Signed-off-by: aeon-x <[email protected]>

* update proto

Signed-off-by: aeon-x <[email protected]>

* fix review comments

Signed-off-by: aeon-x <[email protected]>

* fix review comments for autoscaling

Signed-off-by: aeon-x <[email protected]>

* fix lint

Signed-off-by: aeon-x <[email protected]>

---------

Signed-off-by: aeon-x <[email protected]>
Co-authored-by: Rui Zhang <[email protected]>
Signed-off-by: Ifta Khairul Alam Adil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants