Here's a pull request that looks like cleanup. A queue worker has scaled with KEDA for a year. The team wants to move it to a plain HorizontalPodAutoscaler, so the PR deletes the ScaledObject and adds an HPA with minReplicas: 2. The Deployment manifest doesn't change. It never set spec.replicas, because KEDA owned that number.
Review is quick. One file removed, one added, CI green.
If the queue was empty when it merged, the worker was at 0 replicas, and it stays there. Nothing errors, so nothing pages until the queue backs up.
What actually happens
Two documented defaults line up.
First, KEDA doesn't hand the replicas back when you delete a ScaledObject. advanced.restoreToOriginalReplicaCount defaults to false. The ScaledObject spec reference says the default is to keep the replica count "at the same number as it is in the moment of ScaledObject's deletion." KEDA removes the HPA it created and leaves the Deployment alone. If that number is 0, you get 0. And since minReplicaCount also defaults to 0, scale to zero is what you get out of the box.
Second, the new HPA won't pick it up. The Kubernetes docs call this implicit maintenance-mode deactivation. When the target's replica count is 0 and the HPA's minimum is above 0, the HPA stops adjusting the target and sets its ScalingActive condition to false. It waits until someone scales the Deployment by hand or changes the HPA's minimum.
So the worker sits at zero next to an HPA that looks normal in kubectl get hpa unless you read its conditions.
You don't need a new HPA to hit this. Delete a ScaledObject to "turn off autoscaling for now" and a workload KEDA had at zero stays at zero.
Why review doesn't catch it
The diff only shows the ScaledObject going away. The number that matters, the Deployment's current replica count, lives in the cluster and not in Git. Someone reading YAML can't see that KEDA scaled the worker to 0 at 2 AM.
The behavior is documented, but it sits in the advanced section of the ScaledObject reference. That's not a page most people reread before deleting one.
How to check by hand
Everything below is read-only.
This lists every ScaledObject with its target, the target's current replica count, and whether KEDA will restore replicas on deletion:
kubectl get scaledobjects -A -o json \ | jq -r '.items[] | [.metadata.namespace, .metadata.name, (.spec.scaleTargetRef.kind // "Deployment"), .spec.scaleTargetRef.name, (.spec.advanced.restoreToOriginalReplicaCount // false)] | @tsv' \ | while IFS=$'\t' read -r ns so kind target restore; do echo "$ns/$so -> $kind/$target replicas=$(kubectl -n "$ns" get "$kind" "$target" -o jsonpath='{.spec.replicas}') restore=$restore" done Any line with replicas=0 restore=false is a workload that stays at zero if its ScaledObject is deleted right now.
The pause annotation does the same thing on purpose. autoscaling.keda.sh/paused-replicas: "0" scales the target to 0 and holds it there. To find those:
kubectl get scaledobjects -A -o json \ | jq -r '.items[] | select(.metadata.annotations["autoscaling.keda.sh/paused-replicas"] == "0") | .metadata.namespace + "/" + .metadata.name' And if an HPA has already given up, its conditions say so. ScalingDisabled is the zero-replica case:
kubectl get hpa -A -o json \ | jq -r '.items[] | .metadata.namespace + "/" + .metadata.name + " " + ([.status.conditions[]? | select(.type == "ScalingActive" and .status == "False") | .reason][0] // empty)' What to do about it
Pick one before the PR that deletes the ScaledObject merges.
The safest one is to turn on restore first. Set advanced.restoreToOriginalReplicaCount: true on the ScaledObject and apply that in its own change. KEDA reads the setting when it finalizes the deletion, so it has to be on the live object, not only in the PR that removes it. With it set, KEDA puts the Deployment back to the count it had before KEDA took over.
Or set the number yourself. Add spec.replicas to the Deployment in the same PR. The apply that removes the ScaledObject also writes a real replica count, so the worker comes back up. Once the new HPA is scaling it, you can drop spec.replicas again; the Kubernetes docs on migrating Deployments to an HPA cover how to do that without a dip.
If you only want a break from autoscaling, don't delete anything. Use autoscaling.keda.sh/paused-replicas with the count you want, and remove the annotation when you're done.
After the merge, check that the number you expect is the number you have:
kubectl -n <namespace> get deploy <name> -o jsonpath='{.spec.replicas}{"\n"}' We turned this into a pull-request check after reading KEDA's deletion path. The sample PR report shows what the KEDA findings look like.
