The simplest way to steer a Pod: label the nodes, then ask for a label.
Label the nodes
Chapter 2 labelled a node once. Nodes are cluster-scoped objects and take labels like Pods do:
kubectl label node peaks-node-2 disk=ssd
kubectl label node peaks-node-3 disk=hdd gpu=true
kubectl get nodes --show-labels
kubectl get nodes -l disk=ssdSome labels are already there. kubernetes.io/hostname is the node's name, kubernetes.io/os and kubernetes.io/arch describe the machine. The rest are yours: zone, disk, gpu, whatever the fleet needs.
Ask for a label
spec:
nodeSelector:
disk: ssd
containers:
- name: db
image: postgres:16Every key in nodeSelector must match a label on the node, with that exact value. Extra labels on the node are fine. A node without the label is filtered out.
When nothing matches
The Pod stays Pending and the scheduler says so:
0/3 nodes are available: 3 node(s) didn't match Pod's node affinity/selector.Nothing is wrong with the Pod. Label a node and it schedules a moment later; the scheduler retries Pending Pods whenever the cluster changes.
kubectl label node peaks-node-2 disk=nvme --overwriteWhere it fits
A nodeSelector goes in the Pod spec, so for a Deployment it lives under spec.template.spec. Every replica then obeys it, and a rollout moves them if you change it.