Course contentsShow
← Cloud and Infrastructure
Lesson 1349 of 2,98927. Kubernetes Scheduling and ResourcesFree lesson

Node Affinity Operators

Master In, NotIn, Exists, DoesNotExist, Gt, and Lt operators for flexible node matching.

Node Affinity Operators

What you'll learn: You'll master the six operators that give you fine-grained control over how Pods match nodes using node affinity rules.

Node affinity rules rely on operators to define matching logic between label values. Think of these operators as filters that evaluate whether a node's labels satisfy your Pod's placement requirements—like a bouncer checking IDs against different admission criteria.

The Six Operators

In

Matches nodes whose label contains one of the specified values. Example: region In [us-east-1, us-west-2] matches nodes in either region.

NotIn

Matches nodes whose label does not contain any of the specified values. Useful for exclusion: env NotIn [dev, test] avoids development nodes.

Exists

Matches nodes that have the label key, regardless of value. Example: disktype Exists matches any node with a disktype label (even if empty).

DoesNotExist

Matches nodes that lack the label key entirely. Example: deprecated DoesNotExist selects only nodes without a "deprecated" label.

Gt (Greater Than)

Numeric comparison: matches nodes whose label value is greater than the specified number. Example: gpuCount Gt 2 targets nodes with more than 2 GPUs.

Lt (Less Than)

Numeric comparison: matches nodes whose label value is less than the specified number. Example: priority Lt 50 avoids high-priority nodes.

Combining Operators

You can use multiple operators in a single affinity rule to create complex logic: require nodes with SSD storage (disktype In [ssd]) AND more than 16GB memory (memory Gt 16) AND no special restrictions (restricted DoesNotExist).

Key Takeaway: Node affinity operators (In, NotIn, Exists, DoesNotExist, Gt, Lt) give you precise, flexible control over node selection—from simple matching to complex numeric filtering—enabling sophisticated Pod placement strategies.