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

时间:2019-11-25 08:25:15

标签: kubernetes google-cloud-platform

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

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

eu.gcr.io/diaphanum/bonsai-landing:v1

我使用的清单文件是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

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

kubectl apply -f deploy-ironia.yaml

然后出现以下错误:

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

有什么建议可以解决吗?

更新: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

1 个答案:

答案 0 :(得分:2)

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