Kubernetes:验证数据时出错:[ValidationError(Deployment.spec): io.k8s.api.apps.v1.DeploymentSpec 中的未知字段“容器”

Alb*_*sco 4 google-cloud-platform kubernetes

我正在尝试在 GCP 的 Kubernetes 集群中执行我的第一次应用程序部署。

我在容器注册中有我的应用程序的图像。

eu.gcr.io/diaphanum/bonsai-landing:v1
Run Code Online (Sandbox Code Playgroud)

我使用的清单文件是 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
Run Code Online (Sandbox Code Playgroud)

使用以下命令从 GCP shell 进行部署:

kubectl apply -f deploy-ironia.yaml
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

有什么建议可以解决它吗?

更新:1

使用 --validate=false 运行时,消息为:

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
Run Code Online (Sandbox Code Playgroud)

Tha*_*Van 5

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
Run Code Online (Sandbox Code Playgroud)