Kubernetes: Error validating data: [ValidationError(Deployment.spec): unknown field "containers" in io.k8s.api.apps.v1.DeploymentSpec
18,810
deploy-ironia.yaml
file should be :
apiVersion: apps/v1
kind: Deployment
metadata:
name: bonsai-landing
spec:
selector:
matchLabels:
app: bonsai-landing
replicas: 3
template:
metadata:
labels:
app: bonsai-landing
spec:
containers:
- name: bonsai-landing
image: "eu.gcr.io/diaphanum/bonsai-landing:v1"
ports:
- containerPort: 8080
Author by
Admin
Updated on August 21, 2022Comments
-
Admin almost 2 years
I am trying to perform my first deployment of an application in a Kubernetes cluster in GCP.
I have the image of my application in Container Registration.
eu.gcr.io/diaphanum/bonsai-landing:v1
The manifest file I use is deploy-ironia.yaml:
apiVersion: apps/v1 kind: Deployment metadata: name: bonsai-landing spec: selector: matchLabels: app: bonsai-landing replicas: 3 template: metadata: labels: app: bonsai-landing spec: containers: - name: bonsai-landing image: "eu.gcr.io/diaphanum/bonsai-landing:v1" ports: - containerPort: 8080
Use the following command to deploy from the GCP shell:
kubectl apply -f deploy-ironia.yaml
And I get the following error:
error: error validating "deploy-ironia.yaml": error validating data: [ValidationError (Deployment.spec): unknown field "containers" in io.k8s.api.apps.v1.DeploymentSpec, ValidationError (Deployment.spec) : "mandatory" field selector "is missing in io.k8s.api.apps.v1.DeploymentSpec, ValidationError (Deployment.spec): the mandatory field" template "is missing in io.k8s.api.apps.v1.DeploymentSpec]; if you choose to ignore these errors, disable validation with --validate = false
Any suggestions to solve it?
UPDATE:1
When run with --validate=false the message is:
The Deployment "landing" is invalid: * spec.selector: Required value * spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels` * spec.template.spec.containers: Required value