liveBook · Manning

Equality-based label selector

As explained in Kubernetes in Action, Second Edition

An equality-based label selector filters objects by requiring a label value to equal or not equal a specified value.

An equality-based label selector filters Kubernetes objects by requiring a label value to equal or not equal a specified value. Labels become operational when selectors use them to identify a subset of objects for management tasks. section 7.3

Use equality-based selectors to express straightforward label conditions:

  • app=quote selects objects whose app label equals quote. section 7.3
  • app!=quote selects objects whose app label does not equal quote. section 7.3
  • Separate selectors with commas to require every condition; app=quote,rel=canary selects only objects matching both labels. section 7.3

Filtering and deleting matching pods

Run kubectl get pods -l app=quote to list only Quote pods. Add rel=canary as kubectl get pods -l app=quote,rel=canary to narrow the result to the Quote canary. The same selection mechanism can remove matching objects with kubectl delete pods -l rel=canary. section 7.3.1

A nodeSelector is a manifest-level use of equality matching. Each specified node label must match exactly, and nodeSelector cannot express not-equal or set-based conditions; node affinity provides more expressive alternatives. section 7.3.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines equality and inequality, demonstrates combined conditions and commands, and contrasts nodeSelector with more expressive set-based selectors.
Examples
Demonstrates app=quote, app!=quote, combined app=quote,rel=canary, kubectl listings, bulk deletion, and node scheduling.
What it assumes
Assumes labeled Kubernetes objects and basic kubectl usage while treating selector behavior through concrete pod and node examples.
What you can do after
Apply it via kubectl to list or delete matching objects and configure equality-based node scheduling in a pod manifest.
How it connects
Connects label selectors with labels, kubectl, object management, nodeSelector, set-based selectors, and node affinity.

Related concepts

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.