Skip to content
Latchkey

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".

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

Common 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

  1. Confirm which field is immutable from the error.
  2. Delete the existing object so Helm recreates it with the new spec on upgrade.
  3. Re-run the upgrade.
Terminal
kubectl delete deployment my-app -n prod
helm upgrade --install my-app ./chart -n prod

Stop 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.selector and 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →