kubernetes: HPA condition "ScalingLimited" can have a wrong value "TooFewReplicas" while it should not
What happened?
This is the same issue as #79773
The HorizontalPodAutoscaler condition ScalingLimited can have an incoherent status even if the currentReplicas/desiredReplicas is within the range of requested minReplicas/maxReplicas:
$ kubectl describe hpa my-hpa
...
Min replicas: 1
Max replicas: 3
Deployment pods: 1 current / 1 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource utilization (percentage of request)
ScalingLimited True TooFewReplicas the desired replica count is less than the minimum replica count
Here the TooFewReplicas has no sense: the minReplicas is 1 and the current/desiredReplicas is also 1.
What did you expect to happen?
When the current/desiredReplicas number is within the minReplicas/maxReplicas range, the ScalingLimited condition should be False with the DesiredWithinRange reason:
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
How can we reproduce it (as minimally and precisely as possible)?
- Spawn an HPA, with whatever working configurations
- All the conditions are correct
- Update the HPA and only lower the
minReplicasvalue. TheReplicaSetwill be scaled down, same for thecurrent/desiredReplicas - Then the
ScalingLimitedshow this bad status,TooFewReplicasfor reasonthe desired replica count is less than the minimum replica count
With real outputs: Step 1 & 2: HPA is spawned, everything is OK
Min replicas: 3
Max replicas: 5
Deployment pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Step 3: patch the HPA (here minReplicas → from 3 to 2)
While the ReplicaSet isn’t actually scaled down, the ScalingLimited is still OK:
Min replicas: 2
Max replicas: 5
Deployment pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Step 4: the ReplicaSet is scaled down to 2, then the ScalingLimited condition has a bad status:
Min replicas: 2
Max replicas: 5
Deployment pods: 2 current / 2 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
ScalingLimited True ScalingLimited the desired replica count is less than the minimum replica count
Anything else we need to know?
This issues doesn’t happen all the time. Sometimes lowering the minReplicas cause the issue, sometimes not.
Kubernetes version
$ kubectl version
Client Version: v1.24.7
Server Version: v1.24.7
Cloud provider
OS version
No response
Install tools
No response
Container runtime (CRI) and version (if applicable)
No response
Related plugins (CNI, CSI, …) and versions (if applicable)
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (9 by maintainers)
@k8s-triage-robot: Closing this issue, marking it as “Not Planned”.
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
@krisiye @NikitaCloudRuntime Sorry to keep you waiting, I will fix it as soon as possible this week.