Docker how to use boolean value on spec.container.env.value

6/21/2017

Is there a way to pass a boolean value for spec.container.env.value ? I want to override, with helm, a boolean env variables in a docker parent image (https://github.com/APSL/docker-thumbor) : UPLOAD_ENABLED

I made a simpler test

If you try the following 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

And try to create it with kubernetes, you got the following error :

kubectl create -f envars.yaml

the error :

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

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'

It doesn't work with integer values too

-- Damien GOUYETTE
docker
kubernetes
kubernetes-helm

3 Answers

4/29/2020

This works for me.

In my example, one is hardcoded, and the other comes from an env var.

env:
  - name: MY_BOOLEAN
    value: 'true'
  - name: MY_BOOLEAN2
    value: '${MY_BOOLEAN2_ENV_VAR}'

So basically, I wrap single quotes around everything, just in case.

WARNING: Dont use hyphens in your env var names, that will not work...

-- Sagan
Source: StackOverflow

6/22/2017

spec.container.env.value is defined as string. see here: https://kubernetes.io/docs/api-reference/v1.6/#envvar-v1-core

You'd have to cast/convert/coerse to boolean in your container when using this value

-- Chen Fisher
Source: StackOverflow

1/20/2020

Try escaping the value. The below worked for me:

- name: DEMO_GREETING
  value: "'true'"
-- Ziemek
Source: StackOverflow