Interview Prep/Helm/Chart Structure & Metadata

Why must Deployment selector labels never include the chart version or appVersion?

AdvancedConceptChart Structure & Metadata
Answer

spec.selector of a Deployment, StatefulSet and DaemonSet is immutable. If the selector includes helm.sh/chart: shop-1.4.0 or app.kubernetes.io/version, the next chart bump produces a different selector and the upgrade fails:

Error: UPGRADE FAILED: cannot patch "shop-api" with kind Deployment: Deployment.apps "shop-api" is invalid: spec.selector: Invalid value: ...: field is immutable

That is why charts have separate labels (all labels, on metadata) and selectorLabels (only name, instance, component) helpers. Fixing it after the fact requires deleting the Deployment (with --cascade=orphan to keep pods) and re-running the upgrade.

All Helm questions Roadmap: Helm

More on Chart Structure & Metadata