Repository navigation
[Feat] Support KEDA Auto Scaling in Production Stack Operator - #903
Conversation
Signed-off-by: aeon-x <[email protected]>
There was a problem hiding this comment.
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]>
Signed-off-by: aeon-x <[email protected]>
ruizhang0101
left a comment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
is it possible to use job label as well to align with the other triggers?
There was a problem hiding this comment.
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.
Signed-off-by: aeon-x <[email protected]>
Signed-off-by: aeon-x <[email protected]>
…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]>
…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]>
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)specpath,statuspath,selectorpath) to VLLMRuntimeReplicasandSelectorfields toVLLMRuntimeStatus(required by HPA forAverageValuemetric division)AutoscalingConfigstruct with configurable thresholds, timing, and HPA stabilization windowsController (
internal/controller/vllmruntime_controller.go)reconcileScaledObject()— creates/updates KEDA ScaledObject via server-side apply, gated byAutoscalingConfig.EnabledupdateStatus()to setstatus.replicasandstatus.selectorfrom the Deploymentkeda.sh/scaledobjectsandvllmruntimes/scalePrometheus triggers (4 total)
metricType: Value) — controls 0↔1 scaling, always available even with 0 podsAverageValue) —sum(vllm:num_requests_running), threshold: 5/podAverageValue) —sum(rate(vllm:generation_tokens_total[1m])), threshold: 100/podAverageValue) —sum(rate(vllm:prompt_tokens_total[1m])), threshold: 100/podGenerated manifests
autoscalingConfigschemakeda.shand/scalepermissionsExample CR