如何将整个JSON字符串传递给Helm图表值? [英] How to pass entire JSON string to Helm chart value?

查看:391
本文介绍了如何将整个JSON字符串传递给Helm图表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整个JSON字符串传递给Helm图表值?

How can I pass the entire JSON string to a Helm chart value?

我有values.yml,其中config值应包含带有应用程序配置的整个JSON

I have values.yml where the config value should contain entire JSON with a configuration of an application

...
config: some JSON here
...

我需要将此值传递给一个秘密模板,然后将其作为卷安装到Kubernetes容器中.

and I need to pass this value to a secret template and then mount it as a volume to a Kubernetes pod.

{{- $env := default "integration" .Values.env}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Release.Name }}-{{ $env }}
type: Opaque
data:
  config.json: {{ .Values.config | b64enc | quote }}

但是,传递类似'{"redis": "localhost:6379"}'的单引号字符串的明显方法失败了,因为Helm出于某种原因删除了字符串中的所有双引号(即使我将它们转义了),所以我最终得到了{redis: localhost:6379},这不是有效的JSON.

However the obvious approach of passing single quoted string like '{"redis": "localhost:6379"}' fails because Helm for some reason deletes all double quotes in the string (even if I escape them) so I end up with {redis: localhost:6379} which is not a valid JSON.

还有其他可能性如何一次将配置全部传递到Pod,而无需使用tpl功能加载模板文件并使所有需要的字段分别通过values.yml访问吗?

Is there any other possibility how to pass configuration to the pod all at once without loading template files with tpl function and making all needed fields accessible via values.yml separately?

推荐答案

如果.Values.config包含json,则可以在带有{{ .Values.config | toJson | b64enc | quote }}的模板化Secret中使用它.使用toJson将json转换为json似乎很奇怪,但是helm不会将其本地化为json,除非您告诉了它.请参阅SO问题如何使用json变量yaml文件(Helm)中的示例.

If .Values.config contains json then you can use it in your templated Secret with {{ .Values.config | toJson | b64enc | quote }}. It may seem strange to use toJson to convert json to json but helm doesn't natively treat it as json until you tell it to. See the SO question How do I use json variables in a yaml file (Helm) for an example of doing this.

这篇关于如何将整个JSON字符串传递给Helm图表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆