You can constrain a Pod so that it can only run on a particular set of node(s). There are several ways to do this and the recommended approach is to use label selectors.
You can use any of the following methods to choose where Kubernetes schedules specific Pods:
A node selector specifies a map of key/value pairs that are defined using custom labels on nodes and selectors specified in pods.
For the pod to be eligible to run on a node, the pod must have the same key/value node selector as the label on the node.
Note : You cannot add a node selector directly to an existing scheduled pod.
nodeSelector is the simplest way to constrain Pods to nodes with specific labels whereas Affinity and anti-affinity expands the types of constraints you can define. The affinity feature consists of two types of affinity:
- Node affinity functions like the nodeSelector field but is more expressive and allows you to specify soft rules.
- Inter-pod affinity/anti-affinity allows you to constrain Pods against labels on other Pods.
For nodename you can refer to the link for more information.
Node affinity is a property of Pods that attracts them to a set of nodes and as said nodeselector is used to constrain pods. So, you can use Taints and Tolerations.
Taints are opposite in that they allow a node to repel a set of pods. Tolerations are applied to pods, and allow the pods to schedule onto nodes with matching taints.Taints and tolerations work together to ensure that pods are not scheduled onto inappropriate nodes. One or more taints are applied to a node. This marks that the node should refuse any pods that do not tolerate the taints.
You can refer to the links for more information on taints and tolerance.