Skip to content

Labels, Selectors & Metadata

Labels are key-value pairs attached to Kubernetes objects (such as Pods). Selectors are queries used by controllers and Services to identify and group labeled objects.


Match resources with exact key-value pairs (=, ==, !=):

selector:
app: frontend
tier: cache

Filter keys according to a set of values (in, notin, exists):

selector:
matchExpressions:
- { key: environment, operator: In, values: [production, staging] }
- { key: tier, operator: NotIn, values: [legacy] }

Standard labels recommended by the CNCF community:

metadata:
labels:
app.kubernetes.io/name: payment-api
app.kubernetes.io/instance: payment-api-prod
app.kubernetes.io/version: "2.4.1"
app.kubernetes.io/component: backend
app.kubernetes.io/part-of: ecommerce-suite
app.kubernetes.io/managed-by: helm