error validating data: [ValidationError(Pod): unknown field "containers" in io.k8s.api.core.v1.Pod

12,120

I am not sure about the exact issue but it got resolved with proper space indentation

---
apiVersion: v1
kind: Pod
metadata:
 name: nginx
spec:
 containers:
   - name: nginx
     image: nginx

It worked for me now with proper spaces. Mybad

Share:
12,120

Related videos on Youtube

Rocky Hai
Author by

Rocky Hai

Updated on June 04, 2022

Comments

  • Rocky Hai
    Rocky Hai almost 2 years

    I am trying to create some sample kubernetes pod file.

    cat << EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
    name: nginx
    spec:
    containers:
    - name: nginx
      image: nginx
    EOF
    

    But on executing this I am getting below error.

    error: error validating "pod.yaml": error validating data: [ValidationError(Pod): unknown field "containers" in io.k8s.api.core.v1.Pod, ValidationError(Pod): unknown field "na me" in io.k8s.api.core.v1.Pod]; if you choose to ignore these errors, turn validation off with --validate=false

    • Shudipta Sharma
      Shudipta Sharma over 5 years
      If the exact format you have presented in the statement is true, then I have to say that the problem is in the format. See kubernetes.io/docs/concepts/workloads/pods/pod-overview/….
    • Rocky Hai
      Rocky Hai over 5 years
      Thanks @ShudiptaSharma. Its the issue with format. After observing the error for sometime i came to know it is clearly displaying that which fields in pod are not in right space indentation. Oberservation helps :)
  • Anthon
    Anthon over 5 years
    Both version are valid YAML documents. In your question spec is a key in the root level mapping of the YAML file and has the value null, similar containers is a key in that same mapping with as value a list with one entry. In your answer the the value for spec is a mapping which has a key containers. As Kubernetes doesn't know about a root level key containers, it throws an error.