Labels and Selectors are a standard method to group things together.
Labels are key/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users but do not directly imply semantics to the core system. Labels can be used to organize and to select subsets of objects. Labels can be attached to objects at creation time and subsequently added and modified at any time. Each object can have a set of key/value labels defined. Each Key must be unique for a given object.
Labels are properties attached to each item. So you add properties to each item for their class, kind, and size selector to help you filter these items.
Labels
labels:
class: animal
kind: domestic
size: small
labels:
class: animal
kind: wild
size: big
labels:
class: animal
kind: domestic
size: big
Selectors
Selectors help you filter these items, class animal
and kind domestic
.
selector:
class: animal
kind: domestic
In Kubernetes, there are a lot of different types of objects. Pods, Services, ReplicaSets, Deployments, and etc. Over time you may end up having hundreds or thousands of these objects in the cluster. Then you need a way to filter and view different objects by different categories such as to group objects by their type or view objects by applications. Whatever it may be you can group and select objects using labels and selectors for each object attach labels as per your needs.
Annotations are used to record other details for inflammatory purpose such as tool details like, name and version.