skip to Main Content

I tried to create a file but ends up with an error saying "Error from server (BadRequest): error when creating "deployment-definition.yml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.metadata.spec" ". Can anyone help me fix this issue? Thanks

apiVersion: apps/v1
kind: Deployment
metadata:
 name: myapp-deployment
 labels:
     app: myapp
     type: front-end

spec:
  template:
    metadata:
     name: myapp-pod
     labels:
        app: myapp
        type: front-end

     spec:
       containers:
       - name: nginx-container
         image: nginx
    
  replicas: 3
  selector:
     matchLabels:
        type: front-end

2

Answers


  1. There is a problem with your yaml format, I have fixed it

    apiVersion: apps/v1
    kind: Deployment
    metadata:
     name: myapp-deployment
     labels:
         app: myapp
         type: front-end
    
    spec:
      template:
        metadata:
          name: myapp-pod
          labels:
            app: myapp
            type: front-end
        spec:
          containers:
          - name: nginx-container
            image: nginx
      replicas: 3
      selector:
         matchLabels:
            type: front-end
    
    Login or Signup to reply.
  2. Your spec.template.spec section is indented under the spec.template.metadata section. spec.template.spec should be on the same indentation level as metadata.

    # wrong!
    spec:
      template:
        metadata:
         name: myapp-pod
         labels:
            app: myapp
            type: front-end
    
         spec: # <-- needs to be on the same indentation level as metadata above
           containers:
           - name: nginx-container
             image: nginx
    

    If you are still getting the exact same error, spec.template.metadata.spec then:

    • double check you are applying the correct file with the updated change. E.g. ensure you saved the file with the updated fix
    • if you are using other tools that may patch new values into your yaml file before deploying, ensure those aren’t causing the issue. E.g. patching the old error version of the file into your new file

    Other than that, we would probably need more information to help troubleshoot more.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search