liveBook · Manning

Node selector

As explained in Kubernetes in Action, Second Edition

A node selector is a pod scheduling constraint that restricts placement to nodes whose labels match specified criteria.

A node selector is a scheduling constraint that places a pod only on nodes whose labels match specified key-value criteria. Label nodes by capabilities or roles, then set the pod’s spec.nodeSelector field. This keeps workloads such as low-latency storage users, frontends, or GPU software on suitable nodes while allowing Kubernetes to choose among matching nodes. section 7.3.2

Schedule a frontend pod

Label a node with node-role=front-end, then add this constraint to the pod: spec: nodeSelector: node-role: front-end After creation, kubectl get pod kiada-front-end -o wide shows the pod running on the matching node. If several nodes have the label, Kubernetes can select any eligible one rather than binding the pod to a named node.

Use node selectors in several workload relationships:

  • A DaemonSet places pods only on nodes whose labels match the selector in its pod template; changing node labels can bring nodes into or remove them from scope. section 17.1.3
  • Do not confuse a node selector with a pod selector: the former filters eligible nodes, while the latter identifies pods belonging to an object or receiving service traffic. section 7.3.2 section 17.1.3

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines exact label matching in pod and DaemonSet templates, then contrasts it with set-based node affinity.
Examples
Demonstrates frontend placement with node-role labels and DaemonSet placement with gpu=cuda labels.
What it assumes
Assumes basic pods and nodes, while establishing labels and selectors as the scheduling mechanism.
What you can do after
Configure pods and DaemonSets to target labeled nodes, then verify placement and react to label changes with kubectl.
How it connects
Connects node labels, pods, DaemonSets, pod selectors, node affinity, and taints and tolerations.

Also explained in

Compare how 4 books explain node selector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.