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.
1. Selector Types
Section titled “1. Selector Types”Equality-Based Selectors
Section titled “Equality-Based Selectors”Match resources with exact key-value pairs (=, ==, !=):
selector: app: frontend tier: cacheSet-Based Selectors
Section titled “Set-Based Selectors”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] }2. Recommended Kubernetes Labels
Section titled “2. Recommended Kubernetes Labels”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