Skip to content

Node Selectors

Node Selectors (Scheduling)

In Kubernetes, nodeSelector is the simplest way to constrain a Pod to only run on nodes with specific labels.


📄 Example Pod Definition

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
spec:
  containers:
    - name: data-processor
      image: data-processor
  nodeSelector:
    size: Large

This pod will only be scheduled on a node with the label size=Large.


🏷️ Labeling Nodes

You can label a node using:

kubectl label nodes <node-name> <label-key>=<label-value>

Example:

kubectl label nodes node-1 size=Large

⚠️ Limitations

  • nodeSelector uses exact match only (AND logic).
  • You cannot use OR logic (e.g., Large OR Medium).
  • You cannot use inequalities or expressions (e.g., !=Small).
  • For advanced scheduling, see: Node Affinity

🧠 When to Use

  • For simple node filtering based on static labels.
  • If node groups are well-defined (e.g., GPU=true, size=Large).
  • For quick testing or enforcing strict placement.

✅ Summary

Feature Supported by nodeSelector
Match labels ✅ Yes
Match expressions ❌ No
OR logic ❌ No
Chained rules ❌ No

👉 For more flexible scheduling rules (expressions, preferred rules), check out: Node Affinity →