# Error: UPGRADE FAILED: cannot patch "my-release" with kind Deployment: Deployment.apps "my-release" is invalid: spec.selector: Invalid value: v1.LabelSelector{...}: field is immutable

- **ID:** `kubernetes/helm-upgrade-failed-dry-run`
- **Domain:** kubernetes
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A Helm upgrade attempts to modify an immutable field (e.g., spec.selector) on an existing Deployment, which is not allowed by the Kubernetes API.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| helm 3.12 | active | — | — |
| kubernetes 1.27 | active | — | — |
| helm 3.13 | active | — | — |

## Workarounds

1. **Run `kubectl delete deployment my-release` to remove the Deployment, then perform `helm upgrade --install my-release ./chart` to recreate it with the new selector.** (95% success)
   ```
   Run `kubectl delete deployment my-release` to remove the Deployment, then perform `helm upgrade --install my-release ./chart` to recreate it with the new selector.
   ```
2. **If the selector change is unintended, rollback: `helm rollback my-release <revision>` to a version before the change, then modify the chart to avoid immutable field changes.** (85% success)
   ```
   If the selector change is unintended, rollback: `helm rollback my-release <revision>` to a version before the change, then modify the chart to avoid immutable field changes.
   ```

## Dead Ends

- **** — The --force flag in Helm only recreates resources if the release name changes, but does not bypass immutable field validation on existing resources. (80% fail)
- **** — Editing the selector after creation is also rejected by the API; the field is immutable for all operations. (90% fail)
- **** — The old Deployment persists and still has the immutable field; Helm will try to patch it again. (70% fail)
