AKS icon indicating copy to clipboard operation
AKS copied to clipboard

[BUG] Scaling down with Pod Topology Spread Constraints

Open gepsl opened this issue 2 years ago • 13 comments

Describe the bug AKS CA scaling down is not working properly with Pod Topology Spread Constraints enabled when all available nodes already in use by given deployment.

Assuming there is a node eligible for scaling down (due to low resources allocated), it shouldn't be taken into consideration for Pod Topology Spread Constraints calculations while checking whether the pods can be rescheduled on another nodes (by CA 'simulating' kube-scheduler).

Currently, CA is not scaling down with the following message - 'nodeA is not suitable for removal: can reschedule only 0 out of 1 pods'

To Reproduce Steps to reproduce the behavior:

  1. Let's assume there are 3 nodes
  • nodeA
  • nodeB
  • nodeC
  1. Let's assume there is deployment with 3 pods scheduled as below.
Pod Node
xyz-1 nodeA
xyz-2 nodeB
xyz-3 nodeC
  1. Above deployment has Pod Topology Spread Constraints enabled.
topologySpreadConstraints:
      - maxSkew: 1
        minDomains: 2
        labelSelector:
          matchExpressions:
          - key: app.kubernetes.io/instance
            operator: In
            values:
            - xyz
        matchLabelKeys:
        - pod-template-hash
        nodeAffinityPolicy: Honor
        nodeTaintsPolicy: Honor
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
  1. nodeC is a candidate for scaling down due to low resources allocated (below the CA threshold). However, scaling down never happens.

If I'm not mistaken, the autoscaler checks whether it is possible to reschedule pods on other nodes before scaling events. This mean pod xyz-3 would need to be able to be scheduled on nodeA or nodeB. However, seems it violates Pod Topology Spread Constraints maxSkew, as nodeC is not skipped in calculations. Distribution of pods after scaling down could look like this:

Node Number of pods
nodeA 1
nodeB 2
nodeC 0

The skew (=2) for above spread is bigger than maxSkew(=1) and node cannot be scaled down.

Autoscaler logs: node nodeC is not suitable for removal: can reschedule only 0 out of 1 pods

Auto scaling (in this particular case) works fine with no Pod Topology Spread Constrains enabled.

Expected behavior nodeC is skipped in CA kube-scheduler-simulated calculations allowing to scale down. In this case the distribution of pods after scaling operations can looks like below. The skew in this case is equal to 1.

Node Number of pods
nodeA 1
nodeB 2
~nodeC~ ~0~

Environment:

  • Kubernetes version 1.27.9 and 1.28.5

gepsl avatar Apr 10 '24 12:04 gepsl

@GerardLarwa Ack. Do you have an existing support ticket for this ?

kevinkrp93 avatar May 20 '24 21:05 kevinkrp93

@GerardLarwa Ack. Do you have an existing support ticket for this ?

No, I don't.

gepsl avatar May 21 '24 07:05 gepsl

Are there any steps planned regarding this issue?

gepsl avatar Jun 18 '24 07:06 gepsl

Please raise a support ticket and share it here with the exact issue/ description. We can take a look and update you.

kevinkrp93 avatar Jun 18 '24 15:06 kevinkrp93

What @GerardLarwa suggested does seem like a possible scenario.

See function SimulateNodeRemoval, which decides if a node is eligible for removal, which doesn't actually remove the node from the simulation, and the following function findPlaceFor in which it uses a function isCandidateNode to avoid the to-be-removed node chosen. Looking further we find it is indeed not removing the candidate node from any of the simulator, but only filters it out in the results here.

In conclusion, cluster-autoscaler do keep the candidate node in the sandbox when evaluating. This can be a "quirk" for topology spread which relies all nodes in the cluster to decide on filter decision. Will discuss with support team on next actions.

tdihp avatar Sep 13 '24 10:09 tdihp

tracked via https://github.com/kubernetes/autoscaler/issues/8093

kevinkrp93 avatar May 05 '25 16:05 kevinkrp93

Bumping as related work has merged, but likely not rolled out yet.

sjwaight avatar Jun 05 '25 00:06 sjwaight

It is a core autoscaler bug not AKS specific. Fix will be rolled out when the related patch version is available.

kevinkrp93 avatar Jun 05 '25 02:06 kevinkrp93

Fixed in v1.33. The fix in older K8s versions will be available in subsequent patch version releases

kevinkrp93 avatar Aug 28 '25 22:08 kevinkrp93

Hi there :wave: AKS bot here.

Thank you for reporting this bug to the AKS team.

This issue has been tagged as 'fixing' as a bug fix is currently in progress.

When the fix is complete, we will update you with the investigation and fix details.

Thank you!

Fix also in v1.32 - closing

kevinkrp93 avatar Nov 13 '25 21:11 kevinkrp93

Fix also in v1.32 - closing

In which AKS minor version will we see it fixed?

herquan-docusign avatar Nov 19 '25 22:11 herquan-docusign

All AKS K8s 1.32+

kevinkrp93 avatar Dec 10 '25 22:12 kevinkrp93