commonLabels

Add labels and selectors to add all resources.

Add labels and selectors to all resources. If the label key already is present on the resource, the value will be overridden.

Selectors for resources such as Deployments and Services shouldn’t be changed once the resource has been applied to a cluster.

Changing commonLabels to live resources could result in failures.

  1. apiVersion: kustomize.config.k8s.io/v1beta1
  2. kind: Kustomization
  3. commonLabels:
  4. someName: someValue
  5. owner: alice
  6. app: bingo

Example

File Input

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. commonLabels:
  5. someName: someValue
  6. owner: alice
  7. app: bingo
  8. resources:
  9. - deploy.yaml
  10. - service.yaml
  1. # deploy.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: example
  1. # service.yaml
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: example

Build Output

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app: bingo
  6. owner: alice
  7. someName: someValue
  8. name: example
  9. spec:
  10. selector:
  11. app: bingo
  12. owner: alice
  13. someName: someValue
  14. apiVersion: apps/v1
  15. kind: Deployment
  16. metadata:
  17. labels:
  18. app: bingo
  19. owner: alice
  20. someName: someValue
  21. name: example
  22. spec:
  23. selector:
  24. matchLabels:
  25. app: bingo
  26. owner: alice
  27. someName: someValue
  28. template:
  29. metadata:
  30. labels:
  31. app: bingo
  32. owner: alice
  33. someName: someValue