Interview Prep/Kubernetes/Control plane, RBAC, webhooks and autoscaling

`kubectl apply` of a changed Deployment fails with `The Deployment "web" is invalid: spec.selector: Invalid value: v1.LabelSelector{...}: field is immutable`.

BeginnerTroubleshootingControl plane, RBAC, webhooks and autoscaling
Answer

Likely causes → spec.selector cannot change after creation in apps/v1. A chart upgrade or refactor changed labels used in the selector.

Diagnose →

kubectl get deploy web -o jsonpath='{.spec.selector}{"\n"}'
kubectl diff -f web.yaml

Fix → Revert the selector and only add new labels to the template. If it must change, create a new Deployment with a new name, shift traffic, then delete the old one (or delete with --cascade=orphan and recreate, accepting a brief adoption window).

Prevent → Keep selectors minimal and stable (app.kubernetes.io/name, app.kubernetes.io/instance) and never include version labels in them.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Control plane, RBAC, webhooks and autoscaling