---
source: https://iinventedlight.com/library/notes/kubernetes-node-affinity.md
title: "Node affinity constrains Pods to labeled nodes as a hard rule or a weighted preference"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Assigning Pods to Nodes; kubernetes/website (GitHub), Assign Pods to Nodes using Node Affinity (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Kubernetes node affinity"
tags: [kubernetes, node-affinity, nodeSelector, scheduling, labels]
client: Librarian
sources:
  - id: S1
    title: "Assigning Pods to Nodes"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "Assign Pods to Nodes using Node Affinity (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# Node affinity constrains Pods to labeled nodes as a hard rule or a weighted preference
**Answer:** Node affinity lets you constrain a Pod to run on particular nodes, or to prefer particular nodes, by matching node labels. Use `requiredDuringSchedulingIgnoredDuringExecution` for a hard rule and `preferredDuringSchedulingIgnoredDuringExecution` with a weight for a preference.

## When to bother

Often you do not need any constraints; the scheduler will automatically do a reasonable placement. Constrain placement when a Pod must end up on a node with an SSD attached, or to co-locate Pods from two services that communicate a lot into the same availability zone. The options are the `nodeSelector` field, affinity and anti-affinity, the `nodeName` field, and Pod topology spread constraints.

## The two rule types

- `requiredDuringSchedulingIgnoredDuringExecution`: the scheduler can't schedule the Pod unless the rule is met. With `disktype: ssd`, the pod will get scheduled only on a node that has a `disktype=ssd` label.
- `preferredDuringSchedulingIgnoredDuringExecution`: the scheduler tries to find a node that meets the rule, and still schedules the Pod if no matching node is available.

`IgnoredDuringExecution` means that if the node labels change after Kubernetes schedules the Pod, the Pod keeps running.

## Weights

You can specify a weight between 1 and 100 for each preferred rule. The weight is added to the other scores for a matching node, and the Pod goes onto the node with the highest final score.

## See also

- [kubernetes-labels-selectors](https://iinventedlight.com/library/notes/kubernetes-labels-selectors/)
- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)
- [kubernetes-taints-tolerations](https://iinventedlight.com/library/notes/kubernetes-taints-tolerations/)

## Claims

- id: C1
  claim: Required rules block scheduling until met.
  source: S1
  evidence: "The scheduler can't schedule the Pod unless the rule is met."

- id: C2
  claim: Preferred-rule weights range from 1 to 100.
  source: S1
  evidence: "You can specify a weight between 1 and 100"

- id: C3
  claim: Preferred rules try to find a matching node.
  source: S1
  evidence: "The scheduler tries to find a node that meets the rule."

- id: C4
  claim: A required disktype=ssd rule schedules only on matching nodes.
  source: S2
  evidence: "the pod will get scheduled only on a node that has a"

## Sources

- [S1] Assigning Pods to Nodes. Kubernetes docs. https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ . License: CC-BY-4.0. Accessed 2026-11-18.

- [S2] Assign Pods to Nodes using Node Affinity (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity.md . License: CC-BY-4.0. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Assigning Pods to Nodes; kubernetes/website (GitHub), Assign Pods to Nodes using Node Affinity (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
