kubernetes - How to convert YAML to JSON when saving files into container using Kubernetes Configmap
问题描述
We are going to write Helm chart and providing configuration file using configmap.
For some reasons our app is using JSON format configuration file. Currently we provide configuration file in Helm chart's values.yaml like this.
conffiles:
app_conf.json:
...(content in YAML)...
And to make it easy to modify, in values.yaml we use YAML format and in configmap's template we did conversion using "toJson",
data:
{{- range $key, $value := .Values.conffiles }}
{{ $key }}: |
{{ toJson $value | default "{}" | indent 4 }}
{{- end -}}
{{- end -}}
So in values.yaml it's YAML, and in configmap it will be JSON, then in container it will be stored into JSON file.
Our question is,
- Is there a way to convert YAML to JSON when saving files into container? That is, we hope those configuration content could be 1) YAML in values.yaml 2) YAML in configmap 3) JSON file in container
Thank in advance.
解决方案
我不认为有什么开箱即用的,但你确实有选择,这取决于你的动机。
您的应用正在寻找 json,并且已安装 configmap 以供您的应用读取该 json。您的 helm 部署不会修改容器本身。但是您可以将您的应用程序更改为读取 yaml 而不是 json。
如果您希望能够轻松查看 yaml 和 json 版本,您可以创建两个配置映射 - 一个包含 yaml,一个包含 json。
或者,如果您只是希望能够查看用于创建 configmap 的 yaml 是什么,那么您可以使用helm get values <release_name>
来查看用于创建该版本的值(其中将包括conffiles
条目的内容)。
推荐阅读
- java - 标记以 super 为界的泛型类型参数
- python - 用随机噪声替换图像中的颜色值
- dart - angular dart js 与客户端中等待的异步/承诺互操作
- python - 如何解码这个错误?我正在使用 Google API 使用 python 翻译列表
- mysql - MariaDb/Mysql 查询以计算树中的节点并找到最大的节点
- python - 我的颜色图从零发散,但我怎样才能将它移动到颜色条的中心?
- amazon-web-services - 在 AWS Elastic Beanstalk 上安装 bcrypt 失败
- oracle - 如何正确将 dmp 文件从 11g 导入到 18c oracle?ORA-600、IMP58、IMP28
- c# - dotnet core docker 容器不能在 kubernetes 上运行
- c++11 - 无法理解(并修复)为什么存在此警告“重载 xxx 的调用不明确”