liveBook · Manning

Toleration

As explained in Google Anthos in Action

A Kubernetes toleration is pod scheduling configuration that permits a pod to be placed on a node with a matching taint.

A toleration is Pod configuration that allows scheduling onto a node with a matching taint. Taints repel Pods that do not tolerate them; unlike node labels, they do not attract Pods to a node. A toleration permits placement but does not, by itself, direct a Pod there. section 3.4.1

The taint’s effect determines what happens without a matching toleration:

  • NoSchedule prevents the Pod from being scheduled on the node. section 3.2.7
  • PreferNoSchedule tells the scheduler to try to avoid the node. section 3.2.7
  • NoExecute can evict a running Pod when the taint is added. section 3.2.7

Reserve a node for GPU workloads

Apply a taint with `kubectl taint node NODE workload=gpu:NoSchedule`, then add the `workload=gpu` label with `kubectl label node NODE workload=gpu`. Configure the GPU Pod with both a selector for that label and an Equal toleration matching the taint’s key, value, and effect. The selector directs the Pod toward the labeled node; the toleration lets it pass the taint. Verify placement by checking the Pod’s reported node. section 3.4.1

apiVersion: v1
kind: Pod
metadata:
labels:
 run: nginx-gpu
name: nginx-gpu
spec:
containers:
- image: nginx
 name: nginx-gpu
restartPolicy: Always
nodeSelector:
 workload: gpu
tolerations:
- key: "workload"
 operator: "Equal"
 value: "gpu"
 effect: "NoSchedule"

The Pod manifest places `nodeSelector` and `tolerations` together to target and tolerate the GPU node. section 3.4.1

How Google Anthos in Action covers it

How deep it goes
Explains taint effects and matching Pod configuration through manifests, without detailing the scheduler’s matching internals.
Examples
Uses a GPU-only node with a NoSchedule taint, matching Pod toleration, node selector, and placement output.
What it assumes
Assumes familiarity with Pods and deployment manifests while explaining how node-level taints and Pod-level tolerations affect placement.
What you can do after
Operate/configure it with kubectl and a Pod manifest to permit intended workloads on tainted nodes and verify placement.
How it connects
Relates tolerations to node taints, node labels, node selectors, affinity, and the Kubernetes scheduler.

Also explained in

Compare how 4 books explain toleration →

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.