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

sfg*_*ups 2 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
Run Code Online (Sandbox Code Playgroud)

遵循此页面中的示例。

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

谢谢-SR

Osw*_*ann 5

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

我认为这应该是正确的:

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)"]
Run Code Online (Sandbox Code Playgroud)