Labels and Selectors

Labels are the information assigned to kubernetes resources for the purpose of categorizing and distinguishing.

Selectors are then used to filter those resources based on labels.

We have seen this in getting using in replicasets where we specify selectors to select pods to create replicas.

Also we can use --selector while listing resources. For example, listing pods labelled with env=dev.

k get pods --selector env=dev

We can provide multiple labels in --selector separated by commas (,).

k get all --selector env=dev,tier=frontend