Kubernetes Scheduling: Taints, Tolerations and Affinity Explained

Kubernetes Scheduling: Taints, Tolerations and Affinity Explained

Most of the time, you never think about Kubernetes scheduling. You apply a Deployment, the Pods land on nodes, and everything works. Then one day a Pod stays Pending, or three replicas of a critical service all land on the same node, or a GPU node fills up with web servers. That is when scheduling stops being invisible — and when taints, tolerations and affinity become the tools that fix it.

This guide explains how the Kubernetes scheduler decides where a Pod runs, and how to control that decision with the four mechanisms that matter: nodeSelector, node affinity, taints and tolerations, and pod affinity and anti-affinity. You will see runnable YAML for each one, learn the dedicated-node pattern that combines them, and work through the troubleshooting steps for the most common scheduling failures. Every example applies to a standard cluster, and the version notes use Kubernetes 1.37, the current stable release — 1.37.3 as of 25 November 2026 — with 1.38 planned for 16 December 2026. If you are still learning the basics, start with our Kubernetes tutorial for beginners first; the examples here assume you can already apply a manifest and read Pod status.

How the Scheduler Picks a Node

The Kubernetes scheduler is a control plane component with exactly one job: watch for Pods that have no node assigned and pick the best node for each one. It never starts containers itself — it only makes the placement decision and writes it to the API server, and the kubelet on the chosen node does the rest. A Pod with no nodeName set is unscheduled, and the scheduler’s job is to move it from Pending to bound on a node. When it cannot find a suitable node, the Pod stays Pending, and the reason is recorded in the Pod’s events, which is where all scheduling troubleshooting starts.

The scheduler evaluates each unscheduled Pod against every node in two phases: filtering, then scoring. In the filtering phase, nodes that cannot run the Pod are removed. A node fails filtering if it does not have enough free CPU or memory for the Pod’s requests, if it has a taint the Pod does not tolerate, if it fails a node affinity rule, or if it violates a topology constraint. A single failed check eliminates the node entirely. In the scoring phase, the surviving nodes are ranked: spreading Pods of the same workload across nodes and zones, balancing resource usage, preferring nodes that already have the Pod’s images cached, and honouring the weighted preferences in the Pod’s affinity rules. The highest-scoring node wins.

Two consequences of this design matter for everything that follows. First, scheduling is a decision made once, when the Pod is created: the scheduler does not move running Pods to better nodes, and a Pod that was scheduled onto a node stays there until it is deleted or evicted. Second, the mechanisms in this guide operate at different points in that pipeline. Node selectors and affinity are Pod-side rules that say which nodes the Pod wants; taints are node-side rules that say which Pods the node accepts; and the scheduler applies both during filtering, before scoring ever happens.

nodeSelector: The Simple Starting Point

nodeSelector is the simplest scheduling control Kubernetes offers, and for many workloads it is the only one you will ever need. It is a map of labels on the Pod specification: a Pod with a nodeSelector only schedules on nodes that carry every label in the map. The rule is a hard requirement — if no node has the label, the Pod stays Pending, with no fallback. Labels are the foundation here, so the workflow starts by labelling the node:

kubectl label nodes worker-1 disk=ssd
kubectl label nodes worker-2 disk=ssd
kubectl get nodes --show-labels

Then the Pod asks for that label:

apiVersion: v1
kind: Pod
metadata:
  name: ssd-pod
spec:
  nodeSelector:
    disk: ssd
  containers:
    - name: app
      image: nginx:1.27

That is the whole mechanism, and its simplicity is both its strength and its limit. nodeSelector can only express exact matches on a single label value: it cannot say “disk is ssd or nvme”, it cannot say “not in zone A”, and it cannot express a preference. For a small cluster with a simple split — fast-disk nodes and slow-disk nodes, or GPU nodes and CPU nodes — that is enough. For anything more expressive, node affinity is the upgrade, and it uses the same labels nodeSelector uses, so the labelling work you do now carries over directly.

One practical habit: label nodes by what they are, not by which workload you intend to put on them. A label like disk=ssd describes the node and stays true when the workload changes; a label like app=database describes an intention and goes stale the moment the database moves. Node labels are cluster-wide and shared by every team, so treat them as facts about the hardware and the topology — zone, instance type, disk type — and let the Pod specifications express the intent.

Node Affinity: Required and Preferred Rules

Node affinity is the more powerful successor to nodeSelector. It matches Pods to nodes using the same labels, but with richer rules: multiple values, negative matches, and a choice between a hard requirement the scheduler must satisfy and a soft preference it should try to honour. There are two rule types, and the difference between them is the difference between a Pod that schedules and a Pod that stays Pending. requiredDuringSchedulingIgnoredDuringExecution is a hard rule: the Pod will not schedule unless a node matches, and if no node matches, the Pod stays Pending. preferredDuringSchedulingIgnoredDuringExecution is a soft rule: the scheduler tries to place the Pod on a matching node, but will use a non-matching node if nothing else fits, with a weight from 1 to 100 expressing how strongly the scheduler should prefer the match.

The “IgnoredDuringExecution” half of both names is easy to misread, so be clear about it: it means the rule is evaluated when the Pod is scheduled, not afterwards. If a node’s labels change after the Pod is running so that it no longer matches, the Pod is not evicted — the rule is ignored during execution. That is usually what you want, because a label change should not kill running workloads, but it means affinity is a placement control, not a runtime enforcement mechanism. If you need a Pod evicted when a node stops matching, that is a job for taints with the NoExecute effect, covered later in this guide.

The operators available in affinity rules are In, NotIn, Exists, DoesNotExist, Gt and Lt. In and NotIn match a label value against a set of values; Exists and DoesNotExist match on whether the label is present at all; Gt and Lt compare a numeric label value. A required rule that keeps database Pods on fast-disk nodes in a specific zone looks like this:

apiVersion: v1
kind: Pod
metadata:
  name: db-pod
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: disk
                operator: In
                values:
                  - ssd
                  - nvme
              - key: topology.kubernetes.io/zone
                operator: In
                values:
                  - us-east-1a
  containers:
    - name: db
      image: postgres:16

Notice the structure: a nodeSelectorTerms list, where each term is a set of match expressions that must all be true — the expressions within a term are combined with AND, while separate terms are combined with OR. That gives you the expressiveness nodeSelector lacks: “disk is ssd or nvme, in zone us-east-1a” in a single rule. Preferred rules use the same expressions, wrapped in a preference with a weight, and you can combine several preferences with different weights to express a ranking.

Taints and Tolerations: Repelling Pods from Nodes

Node affinity answers the Pod’s question: which nodes do I want? Taints answer the node’s question: which Pods do I accept? A taint is a key, an optional value and an effect, set on a node, and it repels every Pod that does not carry a matching toleration. A toleration is set on the Pod, and it allows the Pod to schedule onto a tainted node — but it never sends the Pod there. That sentence is the one to remember: a toleration allows placement on a tainted node; it does not force placement onto it. The Kubernetes documentation on taints and tolerations puts it as “tolerations allow scheduling but don’t guarantee scheduling”.

You add a taint with kubectl taint, and the trailing minus removes it:

kubectl taint nodes gpu-1 gpu=true:NoSchedule
kubectl describe node gpu-1 | grep -A3 Taints
kubectl taint nodes gpu-1 gpu=true:NoSchedule-

There are three effects. NoSchedule means no new Pod schedules onto the node unless it tolerates the taint; Pods already running there stay. PreferNoSchedule is the soft version: the scheduler tries to avoid the node, but will use it if nothing else fits. NoExecute is the strong version: new Pods are kept off, and running Pods that do not tolerate the taint are evicted. A toleration for NoExecute can carry a tolerationSeconds value, which lets the Pod stay for that long before it is evicted — useful for giving a Pod a grace period to finish draining while a node is taken out of service.

A toleration matches a taint when the keys are the same and the effects are the same, and either the operator is Exists, in which case any value matches and no value should be specified, or the operator is Equal, in which case the values must match too. The default operator is Equal. An empty key with the Exists operator tolerates every taint, which is what some cluster-wide agents such as monitoring and networking daemons use — and what almost nothing else should use, because it defeats the purpose of tainting entirely. The example below tolerates the GPU taint for five minutes after a NoExecute eviction begins:

apiVersion: v1
kind: Pod
metadata:
  name: gpu-job
spec:
  tolerations:
    - key: gpu
      operator: Equal
      value: "true"
      effect: NoSchedule
    - key: maintenance
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  containers:
    - name: trainer
      image: pytorch/pytorch:2.5

Kubernetes also taints nodes itself when something is wrong, and recognizing those built-in taints will save you debugging time. node.kubernetes.io/not-ready is applied when the node stops reporting healthy, node.kubernetes.io/unreachable when the node stops responding, and node.kubernetes.io/memory-pressure, disk-pressure and pid-pressure when the node is running out of the corresponding resource. Cordoning a node applies node.kubernetes.io/unschedulable. Control plane nodes carry the node-role.kubernetes.io/control-plane taint with the NoSchedule effect, which is why your application Pods never land on them.

One more behaviour matters: setting nodeName directly on a Pod bypasses the scheduler entirely, so the Pod is bound to the node you named even if that node carries NoSchedule taints the Pod does not tolerate. If that node also carries a NoExecute taint, the kubelet will eject the Pod unless it has a matching toleration. Manual node assignment is occasionally useful for debugging, but it defeats the scheduler’s job. Prefer affinity and tolerations, and treat nodeName as a debugging tool rather than a deployment strategy.

Pod Affinity and Anti-Affinity: Placing Pods Near or Away from Each Other

Node affinity places Pods relative to nodes. Pod affinity places Pods relative to other Pods, which is the tool for the two placement problems node affinity cannot express: keeping Pods together, and keeping them apart. Pod affinity attracts a Pod to nodes that already run Pods matching a label selector; pod anti-affinity repels it from those nodes. Both use a topologyKey that defines what “together” or “apart” means: kubernetes.io/hostname means the same node, topology.kubernetes.io/zone means the same zone, and you can use any node label as a topology domain.

Anti-affinity is the one most clusters need first, because it solves the most common availability mistake: replicas of the same service landing on the same node. A Deployment with three replicas and no anti-affinity can place all three on one node, and then a single node failure takes the whole service down. A preferred anti-affinity rule spreads the replicas across nodes when possible, while a required rule guarantees it — at the cost of Pods staying Pending if there are not enough nodes. For most services, preferred is the right choice.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app: web
                topologyKey: kubernetes.io/hostname
      containers:
        - name: web
          image: nginx:1.27

Pod affinity, the positive form, is for Pods that work better together: a cache that should sit on the same node as the application that reads it, or a log shipper that should run where the application logs are produced. The same structure applies, with podAffinity instead of podAntiAffinity, and the topologyKey decides the granularity — same node with kubernetes.io/hostname, same zone with topology.kubernetes.io/zone. Be careful with required pod affinity: it can deadlock scheduling if the Pods it depends on cannot themselves schedule, because each Pod waits for the other to land first. Prefer soft rules for affinity, and reserve required rules for anti-affinity, where the failure mode is a Pod staying Pending rather than a scheduling deadlock.

Topology spread constraints are the newer, more precise tool for the same problem, and they are worth knowing about even if you start with anti-affinity. Where anti-affinity says “avoid nodes running this Pod”, a topology spread constraint says “spread Pods matching this selector evenly across the topology domains, allowing a maximum skew of N”. That lets you express “no more than one replica per zone” or “spread evenly across nodes, allowing a skew of one” in a single rule. Use anti-affinity for simple cases and topology spread constraints when you need an even distribution with a hard limit.

The Dedicated-Node Pattern: Combining Taints, Tolerations and Affinity

Each mechanism on its own has a gap. A taint keeps other Pods off a node, but it does not send the intended Pods there — a Pod with the toleration may still schedule on any untainted node. Node affinity sends the intended Pods to the right nodes, but it does not stop other Pods from landing there too. The dedicated-node pattern closes both gaps by combining them: taint the node to repel everything else, label the node, give the intended Pods a toleration so they can land on it, and give them a required node affinity so they can only land there. Together, the four pieces create a node that runs one workload and nothing else.

The canonical use case is a GPU node, or any expensive specialized hardware. Without the pattern, the GPU node fills up with ordinary Pods that do not need a GPU, and the GPU workload that does need it cannot schedule. With the pattern, the setup looks like this. First, label and taint the node:

kubectl label nodes gpu-1 hardware=gpu
kubectl taint nodes gpu-1 dedicated=gpu:NoSchedule

Then the workload carries both the toleration and the affinity:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: trainer
spec:
  replicas: 2
  selector:
    matchLabels:
      app: trainer
  template:
    metadata:
      labels:
        app: trainer
    spec:
      tolerations:
        - key: dedicated
          operator: Equal
          value: gpu
          effect: NoSchedule
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: hardware
                    operator: In
                    values:
                      - gpu
      containers:
        - name: trainer
          image: pytorch/pytorch:2.5
          resources:
            limits:
              nvidia.com/gpu: 1

Walk through what each piece does. The taint keeps every Pod without the toleration off the node, so the expensive hardware is never wasted on workloads that do not need it. The toleration lets the trainer Pods onto the node. The required node affinity means the trainer Pods can only schedule on nodes labelled hardware=gpu, so they never land on a general node by accident — which matters, because the resource limit nvidia.com/gpu would otherwise leave them Pending on a node with no GPU. And the resource limit itself is the final guard: the scheduler will not place a Pod on a node that cannot satisfy its GPU request, so the affinity rule and the resource request agree with each other instead of fighting.

The same pattern applies to compliance and noisy-neighbour problems. A node pool that holds customer data subject to residency rules gets a taint and a zone label, and only the workloads that must run in that zone carry the toleration and affinity. A node pool reserved for a latency-sensitive service gets a taint so batch jobs cannot steal its CPU, and the service gets the matching toleration. The pattern is the same in every case: the taint repels, the toleration permits, and the affinity directs. Leave any one of the three out and the guarantee breaks — a missing taint lets strangers in, a missing toleration locks the intended workload out, and a missing affinity lets the intended workload wander.

A word of caution about scale. Dedicated nodes are expensive, because a tainted node that your workload does not fill sits idle while other workloads queue elsewhere. Reserve the pattern for hardware or compliance reasons that genuinely require isolation — GPUs, licensed software tied to specific nodes, data residency, or workloads that cannot tolerate neighbours. For ordinary availability, preferred pod anti-affinity across zones gives you most of the benefit at none of the cost, and for ordinary resource isolation, resource requests and limits plus namespaces are usually enough.

Troubleshooting: When Pods Stay Pending

A Pod that stays Pending is the scheduler telling you it cannot find a node, and the reason is always in the Pod’s events. Start there before changing anything:

kubectl get pods -o wide
kubectl describe pod web-7d9c4f6b5-x2k4p

Look at the Events section at the bottom of the describe output, and read the “FailedScheduling” warnings. The message is usually specific enough to act on. “0/3 nodes are available: 1 node(s) had taints that the pod didn’t tolerate” means the only nodes with capacity carry a taint your Pod does not tolerate — add the toleration, or remove the taint if it should not be there. “0/3 nodes are available: 3 node(s) didn’t match Pod’s node affinity” means no node satisfies the affinity rule — check the labels with kubectl get nodes –show-labels, and check the rule for a typo in a key or a value. “Insufficient cpu” or “Insufficient memory” means the Pod’s requests exceed what any single node has free — lower the requests, or add capacity.

The most common causes, in the order to check them, are these. First, a label typo: the node has disk=ssd and the Pod asks for disk=SSD, or the label was applied to the wrong node. Labels are case-sensitive, and the scheduler will not tell you that a label almost matches. Second, a taint nobody remembers: someone cordoned a node during maintenance and never uncordoned it, or a node pressure taint appeared when a disk filled up. Check kubectl describe node for taints and conditions before blaming the Pod. Third, resource requests that exceed a single node: a Pod requesting 16 CPUs will stay Pending on nodes with 8 CPUs each, no matter how many nodes the cluster has, because the scheduler places a Pod on one node, not across several. Fourth, a required rule that is too strict: a required anti-affinity rule with three replicas and two nodes can never schedule the third replica, and the fix is to soften the rule to preferred or add a node.

Two more checks cover the remaining cases. If the Pod scheduled fine yesterday and stays Pending today, something changed: compare the Pod specification with the previous revision — our Kubernetes Deployment YAML tutorial covers reading and diffing manifests — and check whether a node was drained, tainted or deleted. And if only some Pods stay Pending while others schedule, look for the difference between them: a missing toleration on one Deployment, a label selector that matches nothing, or a topology spread constraint with a maximum skew the cluster cannot satisfy.

For day-to-day debugging, keep the kubectl commands close at hand — our kubectl cheat sheet collects the inspection commands used in this guide, including describe, logs and the node and Pod listings that make scheduling failures visible. And remember that 1.38, planned for 16 December 2026, is a release to watch rather than a release to rush into: the Kubernetes v1.38 sneak peek lists the planned changes, and as with any minor release, the right move is to read the final release notes and test in a non-production cluster before upgrading anything that schedules your workloads.

Frequently Asked Questions

What is the difference between a taint and node affinity?

A taint is set on the node and repels Pods that do not tolerate it; node affinity is set on the Pod and attracts it to nodes with matching labels. Taints answer the node’s question — which Pods do I accept — while affinity answers the Pod’s question — which nodes do I want. A toleration allows a Pod onto a tainted node but never sends it there, so dedicated nodes need both: a taint plus toleration to keep others off, and required node affinity to direct the intended workload onto the node.

Do tolerations guarantee my Pod will schedule on a tainted node?

No. A toleration only removes the taint as a barrier; the scheduler still checks every other constraint — free CPU and memory, node affinity rules, topology constraints — before choosing a node. A Pod with a toleration for a tainted node may still schedule on an untainted node if that node scores better. If you need the Pod on the tainted node specifically, add a required node affinity rule for the node’s labels as well.

When should I use NoExecute instead of NoSchedule?

Use NoSchedule when you want to stop new Pods landing on a node while leaving the Pods already running there alone — for example, reserving a node for a specific workload going forward. Use NoExecute when running Pods must leave as well, such as when a node is being drained for maintenance or has developed a fault. With NoExecute, add tolerationSeconds to a toleration when a Pod needs a grace period to finish its work before eviction.

Why are my three replicas all on the same node?

Because nothing told the scheduler to spread them. By default the scheduler prefers spreading Pods, but it is a preference in scoring, not a guarantee, and on a small cluster or under load it can place replicas together. Add a pod anti-affinity rule with topologyKey kubernetes.io/hostname, as shown in this guide, to spread replicas across nodes, or use a topology spread constraint with a maximum skew of one for an even distribution. Use a preferred rule if the service must schedule even when nodes are scarce.

Can I change a node’s labels or taints while Pods are running?

Yes, and the effects differ. Changing a label does not evict running Pods, because affinity rules are only evaluated at scheduling time — the “IgnoredDuringExecution” in the rule names means exactly that. Adding a NoExecute taint, by contrast, evicts running Pods that do not tolerate it immediately, subject to their tolerationSeconds. Adding a NoSchedule taint only affects new Pods.

Conclusion

Scheduling in Kubernetes is a filter-then-score decision, and the four mechanisms in this guide give you control over the filter. nodeSelector is the simple hard rule for straightforward label matching. Node affinity adds the expressiveness — multiple values, negative matches, required versus preferred — that real clusters need. Taints and tolerations let nodes repel workloads they should not run, and pod affinity and anti-affinity let you place workloads relative to each other, which is what availability actually depends on.

The habit that ties it together is labelling nodes by what they are and writing Pod specifications that say what the workload needs, then verifying the result with kubectl describe when a Pod stays Pending instead of guessing. Start with the simplest mechanism that solves your problem — usually nodeSelector or a preferred anti-affinity rule — and reach for the combined pattern only when isolation genuinely requires it. And the next time a Pod refuses to schedule, read the FailedScheduling event first: the scheduler has already told you what is wrong.

Scroll to Top