Kubernetes - 找到无效的字段规范错误

时间:2017-10-16 09:26:26

标签: docker kubernetes yaml

尝试在kubernetes中创建POD时出现以下错误。

# kubectl create -f nginx-deployment-prod.yaml 
error: error validating "nginx-deployment-prod.yaml": error validating data: found invalid field spec for v1.ObjectMeta; if you choose to ignore these errors, turn validation off with --validate=false

YAML文件如下:

apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  name: nginx-deployment-prod
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: nginx-deployment-prod
      spec: 
        containers: 
          - 
            image: "nginx:1.7.9"
            name: nginx-deployment-prod
            ports:
          - 
            containerPort: 80

检查YAML,如果它有效或不使用http://www.yamllint.com/;请让我知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

格式化yaml文件时遇到问题:spec应与metadata处于同一级别。

正确nginx-deployment-prod.yaml是:

apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  name: nginx-deployment-prod
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: nginx-deployment-prod
    spec: 
      containers: 
        - name: nginx-deployment-prod
          image: "nginx:1.7.9"
          ports:
            - containerPort: 80