liveBook · Manning

Label selector operator

As explained in Kubernetes in Action, Second Edition

A label selector operator defines how a selector compares a label key and its values, including equality, set membership, existence, and numeric comparison.

A label selector operator defines how Kubernetes compares a label key with one or more values. It lets scheduling rules require, exclude, detect, or numerically compare labels. section 7.3.2

Set-based selector expressions support these operators:

  • In requires a label value to match one listed value; NotIn excludes listed values. section 7.3.2
  • Exists requires the label key, while DoesNotExist requires that the key be absent. section 7.3.2
  • Lt and Gt compare a label value with one numeric value. section 7.3.2
  • Omit values for Exists and DoesNotExist; provide exactly one value for Lt and Gt. section 7.3.2

Exclude labeled nodes

A node-affinity rule can require node-role=front-end while excluding nodes carrying skip-me. If every matching node has skip-me=true, the pod remains Pending. 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
  ...

Shows a set-based selector combining In and DoesNotExist in node affinity. section 7.3.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines six operators, values constraints, combined expressions, and their effect on pod scheduling.
Examples
Uses node-role=front-end, skip-me exclusion, a node-affinity manifest, and a resulting Pending pod.
What it assumes
Assumes labels and selectors; teaches operator semantics and values-field requirements.
What you can do after
Operate/configure pod placement by writing match expressions in node-affinity manifests.
How it connects
Connects labels and label selectors with node affinity 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.