liveBook · Manning

Node selector

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A node selector is a Kubernetes pod scheduling constraint that selects nodes according to their labels.

A node selector constrains where a Kubernetes pod can run by matching labels on nodes. Use it when a workload needs a labeled characteristic, such as an SSD-equipped worker. The scheduler still checks whether the selected node has resources available. section 2.1.3 section 4.1

To schedule a pod on a labeled worker:

  • Inspect node labels with `kubectl get no --show-labels`. If the required label is absent, add it with `kubectl label no kind-worker disktype=ssd`. section 4.1
  • Generate a starting manifest with `kubectl run ssd-pod --image=nginx --dry-run=client -o yaml > ssd-pod.yaml`. Under `spec`, add `nodeSelector:` at the same indentation as `containers:`, with `disktype: ssd` beneath it. section 4.1
  • Create the pod from the manifest, then run `kubectl get po -o wide`. Check the `NODE` column: the worked example shows `ssd-pod` running on `kind-worker`. section 2.1.3 section 4.1

Unlike `nodeName`, a node selector identifies nodes by label, so more than one node can match. A toleration permits scheduling onto a tainted node but does not select that node. Node affinity is another label-based option when a fallback placement is needed. section 4.1.1 section 9.3.3 section 2.1.3

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through inspecting labels, labeling a node, editing pod YAML, and verifying placement; does not detail scheduler internals.
Examples
Uses a `disktype=ssd` label on `kind-worker`, an nginx pod manifest, and `kubectl get po -o wide` output.
What it assumes
Builds on pods, nodes, and scheduler basics while showing how to inspect labels and generate a starting manifest.
What you can do after
Apply it via kubectl and pod YAML to place a workload on a labeled node and verify its placement.
How it connects
Contrasts nodeName and tolerations with node selectors, and identifies node affinity as another label-based scheduling option.

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 Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.