liveBook · Manning

Node selector

As explained in Google Anthos in Action

A Kubernetes node selector is pod scheduling configuration that restricts placement to nodes having specified labels.

A node selector restricts a Pod to nodes with specified labels. Use `spec.nodeSelector` when a workload needs a capability such as fast disk access or a GPU. The scheduler looks for a matching node; if none exists, the Pod cannot be scheduled. section 3.2.7

To place and check a workload:

  • Label an eligible node, for example with `kubectl label node <node-name> disk=fast`. section 3.4.1
  • Set `spec.nodeSelector` to `disk: fast` in the Pod or deployment template. section 3.4.1 section 3.2.7
  • Run `kubectl get pods -o wide` and check the NODE column against the labeled nodes. section 3.4.1
apiVersion: v1
kind: Pod
metadata:
labels:
 run: nginx-fast
name: nginx-fast
spec:
containers:
- image: nginx
 name: nginx-fast
restartPolicy: Always
nodeSelector:
 disk: fast

This Pod manifest shows the selector at `spec.nodeSelector`, matching the node label `disk=fast`. section 3.4.1

A label attracts a matching workload but does not keep other workloads off the node. For a GPU node reserved from workloads without permission to run there, pair the label and node selector with a taint and a matching Pod toleration. Selecting one node by its hostname is possible, but leaves no matching alternative if that node is unavailable. section 3.2.7 section 3.4.1

Node selectors are one input to the default scheduler alongside node affinity and taints and tolerations. They constrain placement; they do not replace the scheduler. section 3.3.2

How Google Anthos in Action covers it

How deep it goes
Works through node labeling, manifest configuration, and placement checks; distinguishes selectors from taints and affinity without implementing scheduler internals.
Examples
Uses a fast-disk NGINX Pod and a GPU Pod with a toleration, then checks their assigned nodes.
What it assumes
Assumes a Kubernetes cluster and familiarity with Pod manifests and kubectl; demonstrates the selector configuration rather than teaching those foundations.
What you can do after
Operate/configure it by labeling nodes, setting `spec.nodeSelector`, and verifying placement with `kubectl get pods -o wide`.
How it connects
Connects node selectors to node labels, kube-scheduler, node affinity, 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 Google Anthos in Action. The section links point to the parts of the book it draws on.