Chapter 1 · Practice 2 of 5
Label every object with the recommended app labels
Why it matters
Services, Deployments, PodDisruptionBudgets and NetworkPolicies all find Pods through label selectors. Inconsistent labels lead to Services that route to nothing, budgets that protect the wrong Pods and policies that miss a workload.
Kubernetes documents a shared set of recommended labels under the app.kubernetes.io prefix:
app.kubernetes.io/name: the application, such ascheckoutapp.kubernetes.io/instance: this installation, such ascheckout-prodapp.kubernetes.io/version: the version you deployedapp.kubernetes.io/componentandapp.kubernetes.io/part-of: where it fitsapp.kubernetes.io/managed-by: the tool that applied it, such as Helm
Keep selectors small and stable. A Deployment's spec.selector cannot be changed after creation, so select on name and instance, never on version, which changes with every release.
To check, run kubectl get pods --show-labels and confirm each Service selects the Pods you expect with kubectl get endpointslices -l kubernetes.io/service-name=<service>.
Example
metadata:
labels:
app.kubernetes.io/name: checkout
app.kubernetes.io/instance: checkout-prod
app.kubernetes.io/version: "4.2.1"
app.kubernetes.io/component: api
app.kubernetes.io/managed-by: helm
spec:
selector:
matchLabels:
app.kubernetes.io/name: checkout
app.kubernetes.io/instance: checkout-prod