Kubernetes Configuration Patterns 101

Vino Alex
2 min readNov 30, 2022

Topic 4: Affinity Rules

You can constrain a Pod to only run on a particular set of node(s). There are several ways to do it.

Node Selector

NodeSelector is the simplest recommended form of node selection constraint. You can add the nodeSelector field to your Pod specification and specify the node labels you want the target node to have. Kubernetes only schedules the Pod onto nodes with each label you specify.

Node Affinity Rules

Affinity and anti-affinity expand the types of constraints you can define. You can indicate that a rule is soft or preferred. Node affinity functions like the nodeSelector field but is more expressive and allows you to specify `soft` rules.

Pod Affinity and Anti-Affinity Rules

You can constrain a Pod using labels on other Pods running on the node (or other topological domain) instead of just node labels, which allows you to define rules for which Pods can be co-located on a node.

IgnoredDuringExecution means that if the node labels change after Kubernetes schedules the Pod, the Pod continues to run.

Affinity Rules

--

--