kubernetes - 使用 toYaml 进行 Helm Chart 配置图模板化
问题描述
我有values.yml文件,其中包含具有以下格式的 mountPaths 列表:
global:
mountPath:
hello:
config: /etc/hello/hello.conf
node: /opt/hello/node.jks
key: /opt/hello/key.jks
cert: /opt/hello/cert.jks
我希望生成的渲染模板是
volumeMounts:
- name: config
mountPath: /etc/hello/hello.conf
subPath: config
- name: node
mountPath: /opt/hello/node.jks
subPath: node
- name: key
mountPath: /opt/hello/key.jks
subPath: key
- name: cert
mountPath: /opt/hello/cert.jks
subPath: cert
我将如何做到这一点?我在deployment.yaml模板文件中尝试了以下内容:
volumeMounts:
{{- range $key, $value := pluck .Values.service_name .Values.global.mountPath.serviceName | first }}
- name: {{ $key }}
mountPath: $value
subPath: {{ $key }}
{{- end }}
我已经运行了以下 helm 命令,但它对我不起作用。如何根据输入完成获取我想要的上述格式?
helm upgrade --install \
--namespace ${NAMESPACE} \
--set service_name=hello \
--set namespace=${NAMESPACE} \
hello . \
-f values.yaml \
解决方案
这是我所做的:
volumeMounts:
{{- range $key, $value := pluck .Values.service_name .Values.global.mountPath | first }}
- name: {{ $key }}
mountPath: {{ $value }}
subPath: {{ $key }}
{{- end }}
helm template --set service_name=hello [...]
似乎完全呈现你想要的。
请注意,我更改了带有 mountPath 字段的行: $value
-> {{ $value }}
,以及带有 range: .Values.global.mountPath.serviceName
->的行.Values.global.mountPath
推荐阅读
- logging - 如何使用 logback 记录 IP 地址?
- scala - 10个最常见的女性名字 - 顺序变化
- .htaccess - htaccess 301 使用多个规则和 utm 参数重定向
- c++ - 项目A依赖共享库B,B依赖C,A不依赖C。当我使用B的API时,警告B找不到C
- c# - Wpf Livecharts - 分隔符步骤值绑定不起作用
- javascript - 如何在 JavaScript 中将大量值转换为 CSV 字符串数组
- node.js - 如何将来自不同文件的所有导出合并为一个?
- c++ - C++ Cygwin CMake 错误:“致命:无法更改为''没有这样的文件或目录”
- c# - 无法从免费 Azure 应用服务连接到远程 SFTP 服务器
- python - 将多边形分割成多个相等的区域