Managing Node affinity
To better understand how Node affinity works in Kubernetes, we need first to take a look at the most basic scheduling options, which are using Node name and Node selector for Pods.
Pod Node name
As we mentioned before, each Pod object has a nodeName
field which is usually controlled by the kube-scheduler. Nevertheless, it is possible to set this property directly in the YAML manifest when you create a Pod or create a controller that uses a Pod template. This is the simplest form of statically scheduling Pods on a given Node and is generally not recommended – it is not flexible and does not scale at all. The names of Nodes can change over time and you risk running out of resources on the Node.
Tip
You may find setting nodeName
explicitly useful in debugging scenarios when you want to run a Pod on a specific Node.
We are going to demonstrate all scheduling principles on an example Deployment object that we introduced in Chapter 11, Deployment...