I am trying to create a kubernetes deployment. Here is the manifest:
server-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 1
selector:
matchLabels:
tier: server
template:
metadata:
labels:
tier: server
spec:
containers:
- image: rocketblast2481/chatto-server
name: server-container
imagePullPolicy: Always
Then I run the following command:
kubectl apply -f=server-deployment.yaml
But then I get the following error:
The Deployment "server-deployment" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"tier":"server"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutabl
CodePudding user response:
It looks like you are trying to update deployment selector. Which is not possible. To update selector first delete existing deployment using. kubectl delete deployment server-deployment Then run kubectl apply -f server-deployment.yml
CodePudding user response:
Once a deployment spec is deployed the selector become immutable, this means you cannot change it by re-apply with updated spec.
Note: In API version apps/v1, a Deployment's label selector is immutable after it gets created.