Kubernetes: How to set boolean type variable in configMap

时光毁灭记忆、已成空白 提交于 2021-02-05 07:08:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/63905890/kubernetes-how-to-set-boolean-type-variable-in-configmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!