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.
More on Chart Structure & Metadata
What files does `helm create mychart` generate and which ones matter?BeginnerWhat are the required fields in `Chart.yaml`?BeginnerWhat is the difference between `version` and `appVersion`?BeginnerWhy should `appVersion` be quoted in `Chart.yaml`?BeginnerWhat does `type: library` vs `type: application` mean?BeginnerWhat is the `kubeVersion` field used for?Intermediate