K8s - Affinitiy and Anti-Affinity
Anti-Affinity refers to "Breaking a relationship based on a similar characteristics".
This affinity can be set at node level and pod level.
Both node and pod affinity has two parameters:
requiredDuringSchedulingIgnoredDuringExecution: Means the scheduler should look for the node matching the nodeAffinity condition mentioned in the pod configuration file.
preferredDuringSchedulingIgnoredDuringExecution: Means the scheduler tries look for the node matching the nodeAffinity condition mentioned in the pod configuration file. If no node is available then the scheduler creates pod on any available nodes.
What is a node affinity?
Node affinity says scheduler to place a pod on a node when one or more condition matches.
Node affinity is very similar to "Node Selector", but under node affinity we can mention one or more conditions.
I have a node labelled as datacenter=Chennai,operating_system=Linux,gpu=True.
Now, I want to schedule a pod onto a node matching all 3 conditions.
Now, the pod is created. Let's make change to the node affinity. Renaming datacenter reference from Chennai to chennai in the pod configuration.
Now the pod stays in the "Pending" state as the scheduler keeps looking for a node matching all the conditions.
Since we mentioned in the pod configuration as "requiredDuringSchedulingIgnoredDuringExecution" it has satisfy all the requirements.
Let's change to "preferredDuringSchedulingIgnoredDuringExecution"
When using preferredDuringSchedulingIgnoredDuringExecution, we need to mention "weight". The scheduler considers the weight of each node and adds the weight to the other scores for that node, and schedules the Pod onto the node with the highest final score.
Comments
Post a Comment