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)?

  1. Spawn an HPA, with whatever working configurations
  2. All the conditions are correct
  3. Update the HPA and only lower the minReplicas value. The ReplicaSet will be scaled down, same for the current/desiredReplicas
  4. Then the ScalingLimited show this bad status, TooFewReplicas for reason the 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)

Most upvoted comments

@k8s-triage-robot: Closing this issue, marking it as “Not Planned”.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.