Labels are properties that we can attach to each item for example for their type, kind, and so on.
Selectors help us in finding these items. You can think of a selector as a filter.
We could label pods based on some attributes i.e. app name, front-end, back-end.
To select only the pods with the label 'front-end', you would use the keyword selector to filter.
We have different types of objects in kubernetes, pods, nodes, services, replicates, deployments, etc.
Over time these objects grow and we need a way to filter them by different categories such as grouping them by their type (pods) or viewing objects by application name (app1, app2) or by their functions (front-end, back-end, etc).

These are the labels:

In this example, once we create the pod, we can use the kubectl with the selector option to view the pods with these labels.


Note: Labels are key-value pair as you can see from the image (app: App1)
Here is another example of how to select pods based on the labels (env, bu for the business unit, and finally all objects)
controlplane ~ ➜ kubectl get pods --selector env=dev
NAME READY STATUS RESTARTS AGE
db-1-d2rmb 1/1 Running 0 33m
app-1-cxw9j 1/1 Running 0 33m
app-1-gd9bb 1/1 Running 0 33m
app-1-rlxdz 1/1 Running 0 33m
db-1-5xxlc 1/1 Running 0 33m
db-1-gkflt 1/1 Running 0 33m
db-1-lpd5d 1/1 Running 0 33m
controlplane ~ ➜
controlplane ~ ➜ kubectl get pods --selector bu=finance
NAME READY STATUS RESTARTS AGE
db-2-kkhkb 1/1 Running 0 34m
app-1-cxw9j 1/1 Running 0 34m
app-1-gd9bb 1/1 Running 0 34m
app-1-zzxdf 1/1 Running 0 34m
app-1-rlxdz 1/1 Running 0 34m
auth 1/1 Running 0 34m
controlplane ~ ➜ kubectl get all --selector env=prod
NAME READY STATUS RESTARTS AGE
pod/db-2-kkhkb 1/1 Running 0 34m
pod/app-1-zzxdf 1/1 Running 0 34m
pod/app-2-ptvcv 1/1 Running 0 34m
pod/auth 1/1 Running 0 34m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/app-1 ClusterIP 10.43.28.163 <none> 3306/TCP 34m
NAME DESIRED CURRENT READY AGE
replicaset.apps/db-2 1 1 1 34m
replicaset.apps/app-2 1 1 1 34m
controlplane ~ ➜ kubectl get all --selector env=prod,bu=finance,tier=frontend
NAME READY STATUS RESTARTS AGE
pod/app-1-zzxdf 1/1 Running 0 34m