Kubernetes - found invalid field spec Error

10/16/2017

Getting the following error while trying create a POD in kubernetes.

# 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

The YAML file is as below :

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

Checked the YAML, if it's valid or not using http://www.yamllint.com/ ; Please let me know how can I get this resolved.

-- Kris
docker
kubernetes
yaml

1 Answer

10/16/2017

You had an issue with formatting your yaml file: spec should be on the same level as metadata.

Correct nginx-deployment-prod.yaml is:

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
-- nickgryg
Source: StackOverflow