liveBook · Manning

Label selector

As explained in Google Anthos in Action

A Kubernetes selector is a label-based condition for identifying resources or choosing eligible nodes or workloads.

A label selector identifies Kubernetes resources by their assigned labels. Labels are key-value attributes used to identify and organize resources; a selector turns matching labels into a dynamic group of targets. section 3.2.6

Selectors serve two distinct purposes:

  • A Service uses a selector to link to the Pods running an application. This lets clients use the Service’s stable DNS name rather than a Pod IP address that can change when the Pod is replaced. section 3.2.6
  • Selectors help constrain which nodes can run a workload. Tolerations and affinity or anti-affinity rules are other scheduling controls. section 3.0 section 3.5

Selecting application Pods

Assign a label such as `app:frontend-webserver` to application resources, then use a matching selector to identify the intended Pods for a Service. The selected targets form a dynamic group as matching resources change. section 3.2.6

How Google Anthos in Action covers it

How deep it goes
Defines labels and selectors and explains dynamic grouping and Service linkage, but does not provide selector configuration syntax.
Examples
Uses `app:frontend-webserver` and `lob=sales` as label examples and a Service selecting application Pods as the linking scenario.
What it assumes
Assumes familiarity with basic Kubernetes resources while explaining labels and selectors before their use with Services.
What you can do after
Apply label selectors to identify Service targets or help control which nodes run specific workloads.
How it connects
Connects selectors to labels, Pods, Services, Kubernetes scheduling, tolerations, and affinity and anti-affinity rules.

Also explained in

Compare how 7 books explain label selector →

Related concepts

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