Docker如何在spec.container.env.value上使用boolean值

Dam*_*TTE 7 docker kubernetes kubernetes-helm

有没有办法为spec.container.env.value传递一个布尔值?我要重写,与掌舵,码头工人,父母图像中的布尔变量ENV(https://github.com/APSL/docker-thumbor):UPLOAD_ENABLED

我做了一个更简单的测试

如果您尝试以下yaml:

apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: true
Run Code Online (Sandbox Code Playgroud)

并尝试使用kubernetes创建它,您收到以下错误:

kubectl create -f envars.yaml
Run Code Online (Sandbox Code Playgroud)

错误 :

error: error validating "envars.yaml": error validating data: expected type string, for field spec.containers[0].env[0].value, got bool; if you choose to ignore these errors, turn validation off with --validate=false
Run Code Online (Sandbox Code Playgroud)

with validate = false

Error from server (BadRequest): error when creating "envars.yaml": Pod in version "v1" cannot be handled as a Pod: [pos 192]: json: expect char '"' but got char 't'
Run Code Online (Sandbox Code Playgroud)

它也不适用于整数值

Che*_*her 7

spec.container.env.value被定义为string.请看这里:https: //kubernetes.io/docs/api-reference/v1.6/#envvar-v1-core

使用此值时,您必须将容器中的/转换/ coerse转换为boolean


Sag*_*gan 6

这对我有用。

在我的示例中,一个是硬编码的,另一个来自环境变量。

env:
  - name: MY_BOOLEAN
    value: 'true'
  - name: MY_BOOLEAN2
    value: '${MY_BOOLEAN2_ENV_VAR}'
Run Code Online (Sandbox Code Playgroud)

所以基本上,我将所有内容都用单引号引起来,以防万一。

警告:不要在环境变量名称中使用连字符,这不起作用......


小智 5

尝试转义该值。以下对我有用:

- name: DEMO_GREETING
  value: "'true'"
Run Code Online (Sandbox Code Playgroud)