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

<p>How to correct this error message?</p>

<pre><code>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
</code></pre>

<p>follow example from this page.</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/define-command-argument-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/define-command-argument-container/</a></p>

<p>Thanks
-SR</p>

<p>Your&mdash;syntactically correct&mdash;YAML results in an incorrect data-structure for kubernetes. In YAML the indentations can affect the structure of the data. See <a href="https://docs.saltstack.com/en/latest/topics/troubleshooting/yaml_idiosyncrasies.html" rel="noreferrer">this</a>. </p>

<p>I think this should be correct:</p>

<pre><code>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)"]
</code></pre>
