Sub topic 11
Taints that Kubernetes adds on its own
You don't have to create every taint yourself. Kubernetes also taints nodes automatically when they have problems. This chapter assumes you know the three taint effects, how tolerations match taints, and how NoExecute eviction works.
Who adds the taints
The node lifecycle controller runs in the control plane. It watches each node's conditions, such as Ready and MemoryPressure, and adds or removes taints to match. The scheduler and the eviction logic then treat these taints like any you added by hand.
The most common built-in taints are:
| Taint key | Effect | Added when |
|---|---|---|
| `node.kubernetes.io/not-ready` | NoExecute | The node's `Ready` condition is `False`. |
| `node.kubernetes.io/unreachable` | NoExecute | The `Ready` condition is `Unknown`, because the controller stopped hearing from the node. |
| `node.kubernetes.io/memory-pressure` | NoSchedule | The node is low on memory. |
| `node.kubernetes.io/disk-pressure` | NoSchedule | The node is low on disk space. |
| `node.kubernetes.io/pid-pressure` | NoSchedule | The node is running out of process IDs. |
| `node.kubernetes.io/network-unavailable` | NoSchedule | The node's network is not configured yet. |
| `node.kubernetes.io/unschedulable` | NoSchedule | The node is cordoned. |
Two points about this table:
- The condition-based taints are removed again when the condition clears.
- Running
kubectl cordon node1adds theunschedulabletaint. Runningkubectl draincordons the node and then evicts its pods.
Cloud providers can also add taints. An example is node.cloudprovider.kubernetes.io/uninitialized, which keeps pods off a new node until the cloud controller has finished setting it up.
Default tolerations on your pods
The two NoExecute taints would evict every pod at once if pods had no tolerations for them. They do have tolerations, because the DefaultTolerationSeconds admission controller adds two to every pod that doesn't already tolerate those taints. Each lasts 300 seconds.
kubectl get pod gpu-job -o jsonpath='{.spec.tolerations}'The pod's spec then contains something like this:
tolerations:
- key: "node.kubernetes.io/not-ready"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 300
- key: "node.kubernetes.io/unreachable"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 300So a pod survives a node outage of up to five minutes before it is evicted and replaced by its controller. This avoids rescheduling everything after a short network blip.
Changing the timing
You can override the default by declaring your own toleration for the same key. The admission controller then leaves it alone. This pod gives up on an unreachable node after 30 seconds, which suits a stateless service that should fail over quickly:
apiVersion: v1
kind: Pod
metadata:
name: fast-failover
spec:
containers:
- name: app
image: nginx
tolerations:
- key: "node.kubernetes.io/unreachable"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 30Leaving out tolerationSeconds makes the pod tolerate the taint forever. A pod that never leaves a dead node usually isn't what you want. Be careful with stateful workloads in the other direction too, because a long timeout delays recovery.
Pressure taints and DaemonSets
Pods with no matching toleration are kept off a node with a pressure taint, which gives the node room to recover. System agents such as log collectors still need to run on those nodes. The DaemonSet controller automatically adds tolerations for these built-in taints to DaemonSet pods. The next chapter covers this.
Inspecting built-in taints
Use the same commands as for taints you added yourself:
kubectl describe node node1 | grep Taints
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taintsDuring an outage you will see node.kubernetes.io/unreachable with both NoSchedule and NoExecute. The controller adds both effects for that key.
Exercise
A node loses network connectivity at 10:00. A pod with no tolerations of its own was running on it, and the node never recovers. About when is the pod evicted, and why?
Show answer
Around 10:05 plus the time the controller takes to notice the node is silent. The controller marks the node unreachable and adds the node.kubernetes.io/unreachable:NoExecute taint. The DefaultTolerationSeconds admission controller gave the pod a 300-second toleration for that taint. The pod is evicted when those 300 seconds run out, and its controller creates a replacement on another node.