field is immutable ☸️ Kubernetes

The Deployment is invalid: spec.selector: Invalid value: field is immutable

You tried to change a field Kubernetes doesn’t allow to change after creation — Deployment selectors, Job templates, Service clusterIP, PVC storage class.

Seen on: Kubernetes

Meaning

Some fields are immutable because changing them would orphan or confuse existing objects. The fix is to delete and recreate the object (or create a new one with a different name). Helm upgrades fail this way when chart labels change.

Common causes

  • Changing spec.selector (labels) of a Deployment/StatefulSet
  • Editing a completed Job’s template
  • Changing PVC storageClassName/size down, Service clusterIP or type-specific fields

⚡ Quick fix

  1. Delete and recreate the object (keep data volumes in mind)
  2. Create it under a new name and switch traffic
  3. For Helm, keep selector labels stable

Detailed fix by platform

Kubernetes

  1. bash
    kubectl delete deployment web --cascade=orphan   # keep pods running
    kubectl apply -f deployment.yaml

How to diagnose

  1. Field — Which path is named?
  2. Diff — kubectl diff -f file.yaml

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.