k8wiz
Kustomize
Medium
Troubleshooting

Why can adding a label through commonLabels make kubectl apply fail for an existing Deployment?

Select your answer:

Show answer and explanation

Answer: It also adds the label to selectors, which can't change on a Deployment

Explanation

commonLabels adds its labels to resources, selectors and pod templates. A new label changes spec.selector, which Kubernetes rejects on an existing Deployment. commonLabels is deprecated in favor of the labels field, which leaves selectors alone unless you ask for them.