Kubernetes : error validating data: found invalid field env for v1.PodSpec;

4/21/2017

I am using below yaml file to create the pod, kubectl command giving below error.

How to correct this error message?

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]
    args: ["HOSTNAME", "KUBERNETES_PORT"]
  env:
  - name: MESSAGE
    value: "hello world"
    command: ["/bin/echo"]
    args: ["$(MESSAGE)"]

kubectl create -f commands.yaml
error: error validating "commands.yaml": error validating data: found invalid field env for v1.PodSpec; if you choose to ignore these errors, turn validation off with --validate=false

follow example from this page.

https://kubernetes.io/docs/tasks/configure-pod-container/define-command-argument-container/

Thanks -SR

-- sfgroups
kubernetes
yaml

1 Answer

4/21/2017

Your—syntactically correct—YAML results in an incorrect data-structure for kubernetes. In YAML the indentations can affect the structure of the data. See this.

I think this should be correct:

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]
    args: ["HOSTNAME", "KUBERNETES_PORT"]
    env:
    - name: MESSAGE
      value: "hello world"
    command: ["/bin/echo"]
    args: ["$(MESSAGE)"]
-- Oswin Noetzelmann
Source: StackOverflow