How to use cluster autoscaler with nodeSelector/node affinity

Shreyas Arani 266 Reputation points
2021-06-14T15:52:15.743+00:00

Hi I have gone through this link https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler for enabling autoscaling of node scaling using cluster autoscalar. My question is that I am having AKS cluster of 3 nodes and I have labelled the nodes manually and deployed the pods on the respective nodes. So when the autoscaling of node happens will the pods get deployed on this new node or will go in pending state?

Basically If I am using nodeSelector/node affinity then how to implement cluster autoscalar?

Any help or suggestions would be appreciated.

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,956 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. KarishmaTiwari-MSFT 18,747 Reputation points Microsoft Employee
    2021-06-16T02:04:26.383+00:00

    Does Cluster Autoscaler (CA) respect node affinity when selecting node groups to scale up?
    CA respects nodeSelector and requiredDuringSchedulingIgnoredDuringExecution in nodeAffinity given that you have labelled your node groups accordingly. If there is a pod that cannot be scheduled with either nodeSelector or requiredDuringSchedulingIgnoredDuringExecution specified, CA will only consider node groups that satisfy those requirements for expansion.

    However, CA does not consider "soft" constraints like preferredDuringSchedulingIgnoredDuringExecution when selecting node groups. That means that if CA has two or more node groups available for expansion, it will not use soft constraints to pick one node group over another.

    You may find this FAQ on Cluster Autoscaler helpful. Let me know if you have further questions.

    1 person found this answer helpful.

  2. SRIJIT-BOSE-MSFT 4,331 Reputation points Microsoft Employee
    2021-07-23T06:24:29.97+00:00

    You can add labels to a node pool during node pool creation. Reference Labels set at the node pool are added to each node in the node pool. These labels are visible in Kubernetes for handling scheduling rules for nodes. Hence even if the node pool is autoscaled all nodes subsequently added will bear the same labels and hence pods with affinity or node selectors defined should not have any issues being scheduled.

    ----------

    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

  3. Shreyas Arani 266 Reputation points
    2021-06-16T04:51:50.457+00:00

    Hi @KarishmaTiwari-MSFT the cluster autoscaler watches for pods that can't be scheduled on nodes because of resource constraints. And then scales the node. But while deploying pods I have used node affinity so that pod get deploys on that particular. After the nodes get scaled the pod should get deployed on that newly scaled node. But how can I give the label of newly scaled node in the pod deployment file even before the node is scaled.

    It would be helpful if you can send a working example.

    Thanks in advance.

    0 comments No comments