Home > OS >  Is it possible to trigger a node scale-up with Pod Affinity/Antiaffinity rules?
Is it possible to trigger a node scale-up with Pod Affinity/Antiaffinity rules?

Time:07-08

I have a nodepool in AKS with autoscaling enabled. Here is a simple scenario I am trying to achieve.

I have 1 node running a single pod (A) with label deployment=x. I have another pod (B) with a podAntiAffinity rule to avoid nodes running pods with deployment=x label.

affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
              - key: deployment
                operator: In
                values:
                - x
          topologyKey: kubernetes.io/hostname

The behavior I am seeing is that Pod B gets scheduled to the same node as Pod A. I would have wanted Pod B to be in Pending state until the autoscaler added a new node that satisfies the podAntiAffinity rule and schedule Pod B to the new node. Is this possible to do?

Kubernetes Version: 1.22.6

-- EDIT--

This example does trigger a node scale up, so it's doing what I expect it to do and that working for me.

CodePudding user response:

The podAntiAffinity example I posted works as expected.

CodePudding user response:

You should change key for search. As I understand, once you select key: deployment, you are looking in deployments, it's not related to the node. Try this example:

podAntiAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    - labelSelector:
        matchExpressions:
          - key: app.kubernetes.io/instance
            operator: In
            values:
              - name-of-deployment
      topologyKey: "kubernetes.io/hostname"
  • Related