Skip to main content
Node selectors are used to specify the nodes where a pod should be scheduled by using labels.

When to use node selectors

Assume you have a pod that requires a GPU, but only Node 1 has a GPU and Node 2 does not. You want to schedule the pod on Node 1. There are two ways to achieve this:

Node Selectors

Simple label-based node targeting. Works well for straightforward single-condition requirements.

Node Affinity

More expressive rules supporting complex conditions such as “large or medium GPU”.

Steps to use node selectors

1

Label the node

Apply a label to the target node using kubectl label nodes.
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes node1 gpu=large
2

Add nodeSelector to the pod spec

Reference the label in the pod definition under nodeSelector.
sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sample-pod
spec:
  containers:
    - name: sample-container
      image: nginx
  nodeSelector:
    gpu: large

Limitations

Node selectors are not flexible enough for complex scenarios. For example, you cannot express “schedule on a node that has a large or medium GPU” using node selectors alone. Use Node Affinity for those cases.

Build docs developers (and LLMs) love