error message
MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
Reason
reason: the essential reason for this problem is that two identical Deployment (one deployed and one to deploy) have different selectors.
scene duplicate
case:
app.yaml
apiVersion: apps/v1 kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 10
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5
after deployment, take a look at the results
$kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
my-app 10/10 10 10 84s
Next, we modify the selector of deployment, which mainly reads </p b>
spec:
replicas: 10
selector:
matchLabels:
app: my-app-change
template:
metadata:
labels:
app: my-app-change
version: v1.0.0
the completion file is as follows :
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 10
selector:
matchLabels:
app: my-app-change
template:
metadata:
labels:
app: my-app-change
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9101"
spec:
containers:
- name: my-app
image: containersol/k8s-deployment-strategies
ports:
- name: http
containerPort: 8080
- name: probe
containerPort: 8086
env:
- name: VERSION
value: v1.0.0
livenessProbe:
httpGet:
path: /live
port: probe
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: probe
periodSeconds: 5
When kubectl
is deployed, the following error occurs:
$kubectl apply -f app.yaml
The Deployment "my-app" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"my-app-change"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
and you can see the selector for deployed:
$kubectl describe deployment my-app
Name: my-app
...
Selector: app=my-app
...
you can see that the deployment name my-app already has a selector and the content is app=my-app. At this time, the reason for the error is that the name of the newly deployed deployment is also MY-app, but the content of the selector is APP = My-app-change.
solution:
1: you can delete the original deployment and then deploy
2: modify the name of deployment instead of repeating
Read More:
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- [Solved] Kubernetes ingress-srv. error: failed calling webhook “validate.nginx.ingress.kubernetes.io”
- kubernetes Error from server (AlreadyExists): error when creating “kubernetes-dashboard.yaml”: serv
- Error husky > pre-commit (node v10.16.3) is reported when git commit is submitted
- [Solved] ERROR: ./depthai_sdk is not a valid editable requirement.
- Zeppelin reported an error. The JDK version is low
- Vscode pylint reported an error of “no member”, but it is running normally
- Json: struct field readyReplicas has json tag but is not exported [How to Solve]
- [Solved] Error: Could not get apiVersions from Kubernetes
- [Solved] Internal error occurred: failed calling webhook “validate.nginx.ingress.kubernetes.io”:
- k8s kubernetes ingress error: endpoints “default-http-backend“ not found
- [Solved] cocopod Error: failed: undefined method `map‘ for nil:NilClass
- Error reporting and resolution of kubernetes installation
- [Solved] kubectl top pod error: error: Metrics API not available
- [Solved] Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest FAILED和cannot install, GOBIN must be an ab
- An error was reported when Maven package was running the packaged jar package: there is no main list attribute in xxx.jar, which can be solved by configuring Maven plugin
- [Solved] Kubernetes Error: failed to list *core.Secret: unable to transform key
- [Solved] Android Project error: import android.support.v4 (V7). App.activitycompat
- Kubernetes create secret Error: Error from server (InternalError): Internal error occurred…
- [ubuntu14.04]Tensorflow: Could not find any downloads that satisfy the requirement