liveBook · Manning

Match expression

As explained in Kubernetes in Action, Second Edition

A match expression is a Kubernetes node-affinity condition consisting of a label key, an operator, and optional values for specifying node label requirements.

A match expression is a node-affinity condition that combines a label key, an operator, and optional values. It selects nodes by testing their labels. section 7.3.2

Use these operators to define the label test:

  • In or NotIn matches whether a label value belongs or does not belong to the values list. section 7.3.2
  • Exists or DoesNotExist tests whether the label key is present; omit values. section 7.3.2
  • Lt or Gt compares a label value with exactly one value. section 7.3.2

Exclude labelled nodes

A node-affinity rule can require node-role=front-end while excluding nodes labelled skip-me: true. Multiple nodeSelectorTerms use OR logic; multiple matchExpressions inside one term use AND logic. section 7.3.2

Listing 7.5 Using a set-based label selector
apiVersion: v1
kind: Pod
metadata:
  name: kiada-front-end-affinity
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:     #1
          - key: node-role              #2
            operator: In                #2
            values:                     #2
            - front-end                 #2
          - key: skip-me                    #3
            operator: DoesNotExist          #3
  ...

A manifest shows matchExpressions selecting front-end nodes whose skip-me label does not exist. section 7.3.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines fields, operators, value constraints, boolean composition, and a scheduling outcome without detailing scheduler internals.
Examples
Uses a front-end pod, node-role labels, skip-me labels, and a Pending pod when no node satisfies the expressions.
What it assumes
Assumes Kubernetes manifests, node labels, label selectors, and node-affinity fields.
What you can do after
Operate/configure pod scheduling by applying node-affinity manifests with kubectl and interpreting Pending results.
How it connects
Connects label selectors, node labels, node affinity, node selector terms, and pod scheduling.

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.