The Purpose of Labels and Selectors in Kubernetes
Logically isolate and group objects inside of Kubernetes with loose coupling.
In short, labels are a way to group and reference an object. For instance, you could group all APIs with a label like type: api
.
Selectors are just a way to reference objects by labels. If we set a selector to type: api
, then it would be referencing all objects with that label.
This turns out to be a wildly useful feature, as you can use it to define relatively complex sets of rules to determine what node a pod would be scheduled onto, or what backend a service should use. It's a phenomenal way to logically isolate and group objects inside of Kubernetes with loose coupling in the way that they are referenced.