Helm "UPGRADE FAILED: ... field is immutable" in CI
Helm sent a patch that changes a field Kubernetes treats as immutable, such as a Deployment's spec.selector or a Job's spec.template. The API server rejects the patch and the upgrade fails.
What this error means
helm upgrade fails with "Error: UPGRADE FAILED: cannot patch "<name>" with kind <Kind>: <field>: Invalid value: ...: field is immutable".
Error: UPGRADE FAILED: cannot patch "my-app" with kind Deployment: Deployment.apps
"my-app" is invalid: spec.selector: Invalid value: ...: field is immutableCommon causes
A selector or label change on an existing object
Editing spec.selector.matchLabels on a Deployment, StatefulSet, or DaemonSet is not allowed once the object exists; Kubernetes rejects the patch.
A change to an immutable Job or PVC field
A Job's pod template or a PersistentVolumeClaim's size/storageClass cannot be patched in place, so the upgrade fails.
How to fix it
Recreate the object instead of patching
- Confirm which field is immutable from the error.
- Delete the existing object so Helm recreates it with the new spec on upgrade.
- Re-run the upgrade.
kubectl delete deployment my-app -n prod
helm upgrade --install my-app ./chart -n prodStop changing immutable fields
Keep selector labels stable across releases. Put rollout-triggering values in pod template labels or annotations, not in the selector.
How to prevent it
- Treat
spec.selectorand other immutable fields as fixed once shipped. - Use annotations or template labels for values that change per deploy.
- Review chart diffs for immutable-field edits before merging.