Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: How to set boolean type variable in configMap

I want to set a boolean variable in configMap (or secret):

apiVersion: v1
kind: ConfigMap
metadata:
  name: env-config
  namespace: mlo-stage
data:
  webpack_dev_server: false

But when I apply it, I get the following error:

The request is invalid: patch: Invalid value: "map[data:map[webpack_dev_server:false] metadata:map[annotations:map[kubectl.kubernetes.io/last-applied-configuration:{ blah blah blah}]]]": unrecognized type: string

I have tried to change the value to Off/No/False, all having the same problem.

It seems that the value of the keys in the data map can only be string, I have tried to change the value to "false", the yaml file is OK, but then the variable becomes a string but not boolean.

what should I do if I want to pass a boolean as value?

like image 569
Ken Tsoi Avatar asked Sep 15 '20 16:09

Ken Tsoi


People also ask

Is it possible to pass ConfigMaps as environment variables?

Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable. Caution: ConfigMap does not provide secrecy or encryption.

Can we use secret in ConfigMap?

Functions can access Kubernetes Secrets and ConfigMaps. Use secrets for things like API keys, authentication tokens, and so on. Use config maps for any other configuration that doesn't need to be a secret.


1 Answers

Values in a ConfigMap must be key-value string values or files.

Change:

data:
  webpack_dev_server: false

To:

data:
  webpack_dev_server: "false"

To your question:

what should I do if I want to pass a boolean as value?

You may handle this in the application, transform from string to bool.

like image 125
Jonas Avatar answered Oct 07 '22 12:10

Jonas