Values.yaml 文件中的 vlaue 出现 helm 错误

Tam*_*mar 3 kubernetes-helm

我正在尝试将 configMap yaml 中的值替换为 value.yaml 文件中的值。

我的values.yaml 文件包含从我的deployment.yaml 文件引用的字段,它们都运行良好,没有任何问题。

我现在试图用从values.yaml 文件中获取的值替换configMap.yaml 中的硬编码值。

当我运行“helm template”命令时,一切正常并且没有显示错误。
但是,当我运行“升级命令”时,它失败并出现以下错误:

Error: UPGRADE FAILED: cannot patch "oct-2-files" with kind ConfigMap:    
"" is invalid: patch: Invalid value: "{\"apiVersion\":\"v1\",\"data\":{\"keys\":\"\\n\\n##server.http.port=4442\\n\\n\\nbase.request.host=https://localhost\\n\\nbase.request.port=8060\\n\\nlte.device.provisioning.simulate.mode=false\\n\\n\\npostgres.cluster=${POSTGRES_CLUSTER}\\n\\npostgres.host=${POSTGRES_HOST}\\n\\npostgres.port=${POSTGRES_PORT}\\n\\npostgres.dbname=${POSTGRES_DB}\\n\\n\\n\\njdbc.user=${POSTGRES_USER}\\n\\njdbc.pass=${POSTGRES_PASS}\\n\\n\\n\\n#spring.data.mongodb.host=${MONGO_HOST}\\n\\nspring.data.mongodb.uri=${MONGO_URI}\\n\\n\\nspring.redis.password=${REDIS_PASS}\\n\\n\\nspring.redis.host=${REDIS_HOST}\\n\\nspring.redis.port=${REDIS_PORT}\\n\\n\\n\\n\\nactivemq.cluster=${AMQ_CLUSTER}\\n\\nactivemq.server.address=${AMQ_HOST}\\n\\nactivemq.server.port=${AMQ_PORT}\\n\\n\\n\\nlocation.mapitem.image_path=/usr/src/octopus/storage/\\n\\n\\n\\n## OCR\\n\\n\\nocr.tesseract.data.path=/usr/src/octopus/backend/tesseract\\n\\n\\n\\n# define if image saving is enabled\\n\\nocr.image.saving.enabled=true\\n\\n\\n# the path for the image storing folder\\n\\nocr.image.path=/usr/src/octopus/storage/\\n\\n\\n# cron pattern for image clean process\\n\\nocr.image.clean.cron.expression=0 0/10 * * * *\\n\\n\\nocr.image.engine=fe\\n\\n\\n\\n## Debugging\\n\\n# To enable debugging activate the desired properties below and restart the\\nbackend container, e.g.:\\n\\n# docker restart octopus-be-dev-1\\n\\n\\n# logging.level.org.springframework.web=DEBUG\\n\\nlogging.level.org.springframework.web=INFO\\n\\n\\n# logging.level.com.mot.nsa=DEBUG\\n\\nlogging.level.com.mot.nsa=INFO\\n\\n\\n# logging.level.root=DEBUG\\n\\nlogging.level.root=INFO\\n\\n\\n# logging.level.org.apache.camel=on\\n\\nlogging.level.org.apache.camel=off\\n\\n\\n# log4j.logger.org.springframework=DEBUG\\n\\nlog4j.logger.org.springframework=INFO\\n\\n\\n# logging.level.org.hibernate=DEBUG\\n\\nlogging.level.org.hibernate=INFO\\n\\n\\n# hibernate.show_sql=true\\n\\nhibernate.show_sql=false\\n\",\"server.http.port\":4442},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{\"meta.helm.sh/release-name\":\"helmoct\",\"meta.helm.sh/release-namespace\":\"default\"},\"creationTimestamp\":\"2022-06-23T07:05:20Z\",\"labels\":{\"app.kubernetes.io/managed-by\":\"Helm\"},\"managedFields\":[{\"manager\":\"kubectl-create\",\"operation\":\"Update\",\"apiVersion\":\"v1\",\"time\":\"2022-03-14T15:50:44Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:data\":{}}},{\"manager\":\"helm\",\"operation\":\"Update\",\"apiVersion\":\"v1\",\"time\":\"2022-06-27T04:35:27Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:data\":{\"f:keys\":{}}}}],\"name\":\"octopus-2-files\",\"namespace\":\"default\",\"resourceVersion\":\"738993\",\"uid\":\"e43715b4-cdb9-4c13-94a4-2877ec975597\"}}":    
**json: cannot unmarshal number into Go struct field ConfigMap.data of type string**
Run Code Online (Sandbox Code Playgroud)

这是我的values.yaml 文件:

version: 164   
dummyhostval: 1.13.19.196   
mainfeport: 9090   
proxyhost: 1.13.19.73   
httpport: 4442    #this is the only value from the configMap yaml
Run Code Online (Sandbox Code Playgroud)

这是我的 configMap yaml:

kind: ConfigMap
apiVersion: v1
metadata:
  name: octopus-2-files
data:
  server.http.port: {{ .Values."httpport" }}
  keys: |


    ##server.http.port=4442


    base.request.host=https://localhost

    base.request.port=8060

    lte.device.provisioning.simulate.mode=false


    postgres.cluster=${POSTGRES_CLUSTER}

    postgres.host=${POSTGRES_HOST}

    postgres.port=${POSTGRES_PORT}

    postgres.dbname=${POSTGRES_DB}
Run Code Online (Sandbox Code Playgroud)

为什么 helm 认为它是一个数字,我该如何克服这个问题?

The*_*ool 9

该错误告诉您不能在配置映射中使用数字。你需要把它全部变成字符串。

无法将数字解组到字符串类型的 Go 结构字段 ConfigMap.data 中

因此引用服务器端口:

server.http.port: {{ .Values.httpport | quote }}
Run Code Online (Sandbox Code Playgroud)