Labels là key-value metadata gắn lên objects. Selectors cho Service, Deployment, NetworkPolicy hoặc kubectl chọn đúng objects. Nếu labels/selectors sai, Service không route traffic hoặc Deployment không quản lý Pods đúng.
Ví dụ:
metadata:
labels:
app: api
tier: backend
spec:
selector:
matchLabels:
app: apiLabel taxonomy nên nhất quán từ đầu: app, component, version, environment, team.
Đừng dùng label tùy hứng cho routing/automation quan trọng.
Labels are key-value metadata attached to objects. Selectors let Services, Deployments, NetworkPolicies or kubectl choose the correct objects. If labels/selectors are wrong, a Service may not route traffic or a Deployment may not manage Pods correctly.
Example:
metadata:
labels:
app: api
tier: backend
spec:
selector:
matchLabels:
app: apiKeep label taxonomy consistent from the start: app, component, version, environment and team.
Avoid casual labels for critical routing/automation.