Interview Prep/Helm/Install & Upgrade Failures

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

AdvancedTroubleshootingInstall & Upgrade Failures
Answer

Likely causes → The chart's selector labels changed: a new label added to selectorLabels, the chart version or appVersion included in the selector, or the release/name override changed.

Diagnose →

kubectl get deploy shop-api -n shop -o jsonpath='{.spec.selector.matchLabels}'; echo
helm template shop ./shop -f values-prod.yaml -s templates/api-deployment.yaml | yq '.spec.selector'

Fix → Revert the selector change if possible. If the change is intended, orphan-delete and redeploy:

kubectl delete deploy shop-api -n shop --cascade=orphan
helm upgrade shop ./shop -n shop -f values-prod.yaml --wait
kubectl delete rs -n shop -l <old-selector>     # after new pods are Ready

Prevent → Separate selectorLabels with only stable labels; unit test them.

All Helm questions Roadmap: Helm

More on Install & Upgrade Failures