We can label our nodes using key-value pairs and use these labels to schedule a pod on a given node. Node selectors have limitations. We can only use a single label and selector to select a pod. We cannot use complex logic to decide which node should be used for scheduling a pod. Example: we cannot specify a pod to be scheduled on a node with compute: high or compute:medium at the same time. For such use cases, we need Node Affinity.

Select a node for a pod

Example: schedule the pod on a node with high compute power.

kubectl label node node01 compute=high

apiVersion: v1
kind: Pod
metadata:
	name: web-pod
spec:
	nodeSelector:
		compute: high
	containers:
		- name: nginx
			image: nginx

Commands