✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes NodeSelector Placement

Kubernetes NodeSelector Placement assigns workloads to nodes using labels, optimizing resource use and meeting infrastructure requirements.

Kubernetes NodeSelector Placement is the simplest mechanism Kubernetes provides for constraining which nodes a Pod may be scheduled onto, using a flat map of label key-value pairs specified in spec.nodeSelector that every candidate node must match exactly. It represents the most direct expression of "run this Pod only on nodes carrying these specific labels," predating the more expressive node affinity system and remaining in wide use today specifically because of its simplicity — for placement rules that are genuinely just exact-match label constraints, nodeSelector requires less boilerplate than the equivalent nodeAffinity expression.

As a hard constraint, nodeSelector participates in the scheduler's candidate evaluation phase — a node lacking any one of the specified labels is eliminated from consideration entirely, with no partial credit or scoring benefit for partially matching.


Syntax and Semantics

Implicit AND Across All Keys

Every key-value pair in nodeSelector must be present on a node, with an exactly matching value, for that node to remain a candidate — the map is implicitly ANDed together, with no way to express OR logic (any single one of several possible labels) without switching to the more expressive nodeAffinity mechanism.

spec:
  nodeSelector:
    disktype: ssd
    zone: us-east-1a

This Pod requires a node labeled with both disktype: ssd and zone: us-east-1a — a node matching only one of the two is still filtered out.

Exact Value Matching Only

nodeSelector supports only exact equality; there is no support for negation ("not this value"), set membership ("one of several values"), or existence checks ("has this key, regardless of value") — any of these require nodeAffinity's richer operator set (In, NotIn, Exists, DoesNotExist, Gt, Lt) instead.


Common Use Cases

Hardware-Specific Scheduling

Directing workloads to nodes with specific hardware characteristics — disktype: ssd for I/O-sensitive applications, gpu: "true" for GPU-dependent workloads — is the most common use of nodeSelector, relying on node labels applied either automatically by cloud provider integrations or manually by cluster operators.

kubectl label nodes node-worker-05 disktype=ssd

Environment or Tier Segmentation

Some clusters label nodes by intended workload tier (tier: frontend, tier: backend) to keep certain application classes physically separated across dedicated node pools, using nodeSelector on the corresponding Pod templates to enforce that separation.

Compliance and Data Residency

Labeling nodes by physical region or availability zone and constraining specific workloads to run only within a designated region is a straightforward way to satisfy data residency requirements using nodeSelector alone, without needing more complex topology-aware scheduling features.


Limitations Driving Adoption of nodeAffinity

No Soft/Preferred Variant

nodeSelector has no equivalent to preferredDuringSchedulingIgnoredDuringExecution — it is always a hard requirement. A workload that would prefer SSD-backed nodes but can tolerate running elsewhere if none are available cannot express that preference through nodeSelector alone and must use nodeAffinity's preferred variant instead.

No Expression-Based Matching

Workloads needing to match against a set of acceptable values (zone in [us-east-1a, us-east-1b, us-east-1c]) cannot express this through nodeSelector's exact-match-only model, and require nodeAffinity's In operator.


Interaction with Other Placement Mechanisms

Combined with Tolerations

nodeSelector only opts a Pod into a labeled subset of nodes; it does not, by itself, override any taints those nodes carry. A Pod targeting a tainted node pool via nodeSelector still needs matching tolerations to actually be scheduled there — the two mechanisms are complementary, not substitutes for each other.

spec:
  nodeSelector:
    gpu: "true"
  tolerations:
    - key: "nvidia.com/gpu"
      operator: "Exists"
      effect: "NoSchedule"

Coexistence with nodeAffinity

Both nodeSelector and nodeAffinity can be present simultaneously on the same Pod spec, in which case both must be satisfied — nodeSelector is evaluated as an additional hard constraint alongside whatever nodeAffinity rules are also specified, rather than one replacing the other.


Example

apiVersion: v1
kind: Pod
metadata:
  name: codartium-nodeselector-example
spec:
  nodeSelector:
    disktype: ssd
    zone: us-east-1a
  containers:
    - name: app
      image: codartium/app:latest
      resources:
        requests:
          cpu: "250m"
          memory: "256Mi"
kubectl get nodes --show-labels
kubectl label nodes node-worker-03 disktype=ssd zone=us-east-1a