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

1/27/2019

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

-- Rocky Hai
kubernetes
pod
yaml

1 Answer

1/27/2019

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

-- Rocky Hai
Source: StackOverflow