Sobes.tech
Junior — Middle

Can you explain the differences between Label and Selector in Kubernetes and their roles in resource management?

sobes.tech AI

Answer from AI

In Kubernetes, Label is a key-value pair assigned to objects (such as pods, services) for identification and organization. Labels are used to tag resources so they can be grouped and filtered.

Selector is a mechanism for selecting objects based on their Labels. A selector sets criteria (for example, "app=frontend") to choose all objects with matching labels.

Role:

  • Labels help tag resources.
  • Selectors allow managing groups of resources, for example, a service selects pods via a selector to direct traffic.

Example:

labels:
  app: frontend
  tier: web

selector:
  matchLabels:
    app: frontend

Here, the selector will select all objects with the label app=frontend.