Kubernetes 101 : Node affinity - scheduling pods on specific nodes -
Node affinity is used to tell kubernetes on which node a pod or a group of pods should be scheduled, bypassing the "normal" scheduling process.
To instruct kubernetes to only deploy pods on nodes labeled "memory: slow", we could use the affinity parameters in the pod's Yaml file as below:
The "requiredDuringSchedulingIgnoredDuringExecution" is a "hard" type of affinity which means that our pod will be deployed only on nodes that have the label "memory: slow".
For pods with less restrictive scheduling, we could use the "preferredDuringSchedulingIgnoredDuringExecution" type of affinity which is a "softer" requirement.
That means that deploying our pod on nodes with the label "memory: slow" is preferred but not compulsory.
The weight parameter is made up of values that add up to make the "score" of a node each time a node fulfills the requirements of a particular weight.
The node with the highest "score" is chosen for hosting the pod.
In the below example, the node that has the "memory: slow" label gets a "10" score and the node that has both the "memory: slow" and the "CPU: fast" labels gets a "25" score.
We could also use the "operator" field in the pod's Yaml file in conjunction with these predefined values : NotIn, Exists, DoesNotExist, ...
for example, the below parameter tells kubernetes not to schedule a pod on a node with the label "node_label":