{
  "id": 8192730,
  "title": "Node Selectors and Node Affinity: Telling the Scheduler Where Pods Can Run",
  "url": "https://urgent.news/2026/09/18/node-selectors-and-node-affinity-telling-the-scheduler-where-pods-can",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-18T06:25:26.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/siddharthajmore/node-selectors-and-node-affinity-telling-the-scheduler-where-pods-can-run-1loj"
  },
  "original_language": "en",
  "account": "Node selectors and node affinity are two Kubernetes features that help specify where a pod can run based on node labels. Node selectors use a simple key-value matching approach, while node affinity offers more advanced rules such as IN, NotIn, Exists, DoesNotExist, Gt, and Lt.\n\nNode affinity can be applied in two ways: requiredDuringSchedulingIgnoredDuringExecution (a hard rule, similar to node selectors) and preferredDuringSchedulingIgnoredDuringExecution (a soft rule that nudges the scheduler's scoring without blocking the pod). The latter allows you to assign a weight (1-100) to influence the scheduler's decision.\n\nOne pitfall to be aware of is the distinction between matchExpressions and matchFields. matchExpressions work with node labels, while matchFields operate on node fields, like the node's name. It's generally recommended to use matchExpressions and labels rather than matchFields, as the latter is typically used for pinning a pod to a specific node by name.\n\nNode selection is relevant in scenarios where certain nodes have specific capabilities, such as GPU-equipped nodes for GPU-intensive workloads, SSD-backed storage for databases or caches, or specific zones for compliance or licensing reasons. In such cases, using node selectors or node affinity is essential to ensure proper scheduling of pods.\n\nBoth node selectors and node affinity are evaluated during the filtering phase of the scheduler. Nodes that don't match the specified labels are removed before the scoring phase begins. The affinity rule with the preferredDuringSchedulingIgnoredDuringExecution setting does not participate in the filtering phase; instead, it adds its weight to a node's score if the node matches.\n\nAn important characteristic of both mechanisms is that they are IgnoredDuringExecution. This means that changes to node labels or fields after a pod has been scheduled do not affect the already running pod.\n\nNode selectors are simpler and easier to read, making them suitable when the requirement is straightforward, i.e., a pod must have a specific label. On the other hand, node affinity provides more flexibility for complex scenarios involving OR logic, negation, or preferential scheduling. However, it's essential to remember that pod-to-pod placement and workload distribution are not addressed by these features. Those are covered by pod affinity and anti-affinity, which will be discussed in a later part of this series.\n\nA common mistake when dealing with node selectors and node affinity is setting a required rule without any matching nodes, causing the pod to remain in a Pending state indefinitely. In such cases, reviewing the Events section of the pod using kubectl describe pod can help identify the scheduling failure reason. Another lesser-known issue is that changes to node labels or fields after a pod has been scheduled do not impact the running pod, as these mechanisms are IgnoredDuringExecution.",
  "summary": "TL;DR nodeSelector matches a pod to a node using labels. Simple, exact match, nothing fancier. Node affinity does the same job with more expressive rules: In , NotIn , Exists , DoesNotExist , Gt , Lt . Affinity comes in two flavors: required (hard rule) and preferred (soft nudge, weighted). IgnoredDuringExecution means once the pod's running, label changes on the node don't touch it. No eviction,…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}