Kubernetes:错误验证数据:发现v1.PodSpec无效字段env;

时间:2023-01-15 00:02:50

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

我正在使用下面的yaml文件创建pod, kubectl命令给出以下错误。

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/

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

Thanks -SR

谢谢老

1 个解决方案

#1


2  

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.

语法纠正- yaml导致kubernetes的数据结构不正确。在YAML中,缩进会影响数据的结构。看到这个。

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)"]

#1


2  

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.

语法纠正- yaml导致kubernetes的数据结构不正确。在YAML中,缩进会影响数据的结构。看到这个。

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)"]