Kubernetes:错误验证数据:找到v1.PodSpec的无效字段env;

时间:2017-04-21 02:34:15

标签: yaml kubernetes

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

如何更正此错误消息?

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

按照此页面中的示例进行操作。

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

由于 -SR

1 个答案:

答案 0 :(得分:3)

你的语法正确-YAML会导致kubernetes的数据结构不正确。在YAML中,缩进可能会影响数据的结构。见this

我认为这应该是正确的:

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)"]
相关问题