Affinity and anti-affinity
Even though nodeSelector is simple and flexible, it's still inept at expressing the complicated needs of real-world applications. For example, we usually don't want pods of a StatefulSet be put in the same availability zone to satisfy cross-zone redundancy. It can be difficult to configure such requirements with only node selectors. For this reason, the concept of scheduling under constraints with labels has been extended to include affinity and anti-affinity.
Affinity comes into play in two different scenarios: pods-to-nodes and pods-to-pods. It's configured under the .spec.affinity path of a pod. The first option, nodeAffinity, is pretty much the same as nodeSelector, but formulates the relation between pods and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access