【问题标题】:How to read a value from json through Helm charts如何通过 Helm 图表从 json 中读取值
【发布时间】:2018-12-20 11:20:13
【问题描述】:

我在 json 文件中定义了值。

cat templates/encrypt.json
{"encrypt": "cg8StVXbQJ0gPvMd9o7yrg=="}

该值必须传递给 yaml 文件,如下所示

-config-file={{ tpl (.Files.Get "encrypt.json") . | b64enc }}  \

下面是舵图sn-p

exec /bin/consul agent \
            -node="${NODE}" \
            -advertise="${POD_IP}" \
            -bind=0.0.0.0 \
            -client=0.0.0.0 \
            {{- if .Values.client.grpc }}
            -hcl="ports { grpc = 8502 }" \
            {{- end }}
            -config-dir=/consul/config \
            {{- range .Values.client.extraVolumes }}
            {{- if .load }}
            -config-dir=/consul/userconfig/{{ .name }} \
            {{- end }}
            {{- end }}
            -datacenter={{ .Values.global.datacenter }} \
            -data-dir=/consul/data \
            -config-file={{ tpl (.Files.Get "encrypt.json") . | b64enc }}  \
            {{- if (.Values.client.join) and (gt (len .Values.client.join) 0) }}

当我运行我的健康图表时,我收到以下错误。

Error: unable to decode "": Object 'Kind' is missing in '{"encrypt":"cg8StVXbQJ0gPvMd9o7yrg=="}'

【问题讨论】:

    标签: kubernetes kubernetes-helm


    【解决方案1】:

    您使用{{ tpl (.Files.Get "encrypt.json") . | b64enc }} 注入的是json 的内容,即{"encrypt": "cg8StVXbQJ0gPvMd9o7yrg=="}。但我认为这不是该参数所期望的。它似乎期望 Pod 中应该可用的文件的文件名,这可以通过挂载 configmap 来完成。那是how the consul helm chart in the official kubernetes charts handles it:

                {{- if .Values.Gossip.Encrypt }}
                if [ -e /etc/consul/secrets/gossip-key ]; then
                  echo "{\"encrypt\": \"$(base64 /etc/consul/secrets/gossip-key)\"}" > /etc/consul/encrypt.json
                  GOSSIP_KEY="-config-file /etc/consul/encrypt.json"
                fi
                {{- end }}
    

    lets the user set a gossip key in the values filesets that in a secretmounted into Pods as a volume。如果可以的话,我建议您遵循该图表的方法。

    我猜你正在做的是建立在the consul helm chart that Hashicorp provides 之上,因为你包含的代码与此类似。因此,您可能无法使用 kubernetes 存储库中的那个,但您应该能够遵循该图表为此配置文件采取的方法。

    【讨论】:

      猜你喜欢
      • 2017-05-23
      • 2020-04-21
      • 2019-07-10
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      • 2020-07-08
      • 2022-11-03
      • 1970-01-01
      相关资源
      最近更新 更多