Node Affinity

Node affinity is a more expressive form of the nodeSelector specification, which includes two sets of constraints:

  • requiredDuringSchedulingIgnoredDuringExecution: This set indicates the constraints that must be satisfied prior to scheduling a pod to a node. This set is similar to nodeSelector; however, it enables more flexible definitions.
  • preferredDuringSchedulingIgnoredDuringExecution: This set indicates the constraints that are preferred during scheduling, but not guaranteed.

In short, the first set consists of the hard limits for the scheduler, whereas the second set consists of the soft limits. The IgnoredDuringExecution part indicates if labels change and constraints are not satisfied during runtime, no changes will be made by the scheduler.
With these node affinity rules, it is easy to define complex rules in order to limit the scheduler. For instance, in the following pod definition with the requiredDuringSchedulingIgnoredDuringExecution group, pods are restricted to run only in a PowerPC environment. In addition, with the preferredDuringSchedulingIgnoredDuringExecution group, pods attempt to run on the nodes in availability zone A if possible:

apiVersion: v1
...
requiredDuringSchedulingIgnoredDuringExecution:
...
spec:
affinity:
- key: kubernetes.io/arch
operator: In
values:
- ppc64_le
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: failure-domain.beta.kubernetes.io/zone
operator: In
values:
- availability-zone-a
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.151.158