Member-only story
Using Affinity with nodeSelector and Policy-As-Code, and Exclusions
This Article was Originally Published at Magalix
https://www.magalix.com/blog/using-affinity-with-nodeselector-and-policy-as-code-and-exclusions
In the age of containerized apps, modern applications leverage microservices packed with configurations and other related dependencies. In a Kubernetes cluster, as part of the control plane, the default scheduler (or the Kube-scheduler) controls the selection of optimal nodes for every newly created pod to run on, including unscheduled pods.
But each container within a pod will have different resource requirements. This means that you have to filter existing nodes according to specific requirements. The default behavior of Kubernetes works well for most use cases. For example, it finds a balance in resource utilization. However, if you want to exact more control over how a pod is used, it requires more advanced features, including node affinity, nodeSelector, and more.
What is nodeSelector?
nodeSelector is the easiest way to select node constraints. As part of the PodSpec field, nodeSelector stipulates a map of key-value pairs. The idea here is to allow a pod to be scheduled if the labels match the labels defined in nodeSelector.