Labels are identifiable metadata for k8s objects. They are formed as key/value pairs under the metadata.labels field. They are especially useful for deeper grouping of Objects under the same Namespace. Objects with labels could be filtered and watched by clients using a Label Selector.

Warning

Labels are not meant for unique identification. It is expected for Objects to share common Labels.

A Label Selector is the core grouping primitive in K8s. The API currently supports two types of selectors:

  • equality-based: env=prod.

Note

By delimiting each predicate with a comma, essentially you are using the logical AND operator: env=dev,app!=controller (this selects Objects in the “dev” environment that either lack the app label or have app set to any value except controller.)

  • set-based: env in (prod, staging).

Warning

For both equality-based and set-based conditions there is no logical OR operator. To select Objects matching multiple values for the same label, use set-based operators: env in (prod, staging).

Note

Both Selector types can be combined.

Important

Services, Deployments, ReplicaSets use a Label Selector to identify which Object/s to manage.

For common Label patterns, refer to the docs link below.

Sources