liveBook · Manning

Taint

As explained in Google Anthos in Action

A Kubernetes node taint is a key-value restriction on a node that repels pods lacking a matching toleration.

A taint marks a node as unsuitable for Pods that lack a matching toleration. It repels workloads; a node label instead gives a Pod’s selector or affinity rule a way to target nodes. Use a taint when a node should be reserved for a class of workloads, such as applications requiring a GPU. Use a label when a workload needs to find a capability, such as fast local storage. A toleration permits placement on a tainted node but does not, by itself, direct the Pod there. section 3.2.7 section 3.4.1

Choose the taint effect according to the scheduling consequence required:

  • NoSchedule prevents a Pod without a matching toleration from being scheduled on the node. section 3.2.7
  • PreferNoSchedule asks the scheduler to avoid placing a Pod without a matching toleration there. section 3.2.7
  • NoExecute evicts an already-running Pod that does not match when the taint is added. section 3.2.7

Reserve a GPU node

In a three-zone GKE cluster, ordinary workloads may run in two zones, while nodes in the GPU zone are reserved for GPU-requiring workloads. Apply `kubectl taint node <gpu-node> workload=gpu:NoSchedule` to each reserved node, then label those nodes `workload=gpu`. A Pod intended for that zone uses `nodeSelector: {workload: gpu}` and a toleration with key `workload`, operator `Equal`, value `gpu`, and effect `NoSchedule`. The selector targets the labeled node; the toleration lets the Pod pass its taint. Check the resulting node assignment in the Pod listing. section 3.4.1

Taints and tolerations are among the criteria used by the default kube-scheduler, alongside node affinity and selectors. Set the restriction on nodes and the matching permission in Pod configuration; do not mistake permission to run on a reserved node for a requirement to run there. section 3.2.7 section 3.3.2

How Google Anthos in Action covers it

How deep it goes
Explains effects and matching tolerations through commands and a Pod manifest, without detailing scheduler internals.
Examples
Uses a three-zone GKE cluster, a GPU-node taint, a matching NGINX Pod toleration, and placement output.
What it assumes
Assumes familiarity with Pods, nodes, manifests, and kubectl while explaining the distinction between attracting and repelling workloads.
What you can do after
Operate/configure it with kubectl to reserve nodes and configure Pods that can run on them.
How it connects
Connects taints to tolerations, node labels, node selectors, node affinity, and kube-scheduler decisions.

Also explained in

Compare how 4 books explain taint →

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.