Kubernetes concepts – selectors
Selectors are used in Kubernetes to connect resources together based on the labels they have (or don’t have). A selector is meant to provide a means to retrieve a set of resources in Kubernetes.
Most of the kubectl
commands support a -l
option that allows you to provide a selector to filter what it finds.
A Selector can be equality-based to represent specific values, or set-based to allow filtering and selection based on multiple values. Equality selectors use =
or !=
. Set selectors use in
, notin
, and exists
. You can combine these in a selector to create more complex filters and selection criteria by appending the selectors together with a ,
between them.
For example, you might use a label app
to represent a grouping of Pods that provide service to a specific application - in this case using the value flask
and tier
to represent the values of front-end
, cache
, and back-end
tiers. A selector that would return all resources related to the app might be:
app=flask...