kubernetes - Helm 继承变量值
问题描述
考虑这个 values.yaml 文件和 secrets.yaml 文件。有没有办法读取
变量的数据(即上面dict的值)并将其prometheus.promethesSpec.thanos.objectStorageConfig.name
传递给secrets.yaml?thanosObjectStoreConfig
值.yaml
prometheus:
prometheusSpec:
thanos:
image: thanosio/thanos:v0.11.0
objectStorageConfig:
name: thanosObjectStoreConfig
key: storage
# Defining storage configs for thanos
thanosObjectStoreConfig:
type: AZURE
config:
storage_account: "xxxxxxx"
storage_account_key: "xxxxxxxxx"
container: "prometheus"
endpoint: "blob.core.windows.net"
max_retries: 0
秘密.yaml
{{- if .Values.prometheus.prometheusSpec.thanos }}
---
apiVersion: v1
kind: Secret
metadata:
name: thanos-object-store-config
type: Opaque
data:
storage: < should contain values of `thanosObjectStorageConfig` | b64enc >
# Tried not working as expected
# storage: {{ tpl .Values.prometheus.prometheusSpec.thanos.objectStorageConfig.name $ }}
{{ end }}
解决方案
最简单的方法是完全避免这个问题。当您helm install
或helm upgrade
图表时,您可以提供任意数量的-f
选项来指定额外的 YAML 值文件。您可以将特定的存储配置(thanosObjectStoreConfig
顶级密钥下的内容)放在单独的文件中,使用固定的顶级密钥,并helm install -f
在不同的环境中使用不同的文件。
helm install -f values-production.yaml ...
如果你真的想基于一个键来切换它,核心 Go文本/模板语言包含一个index
可以进行动态查找的函数:
{{- $key := .Values.prometheus.prometheusSpec.thanos.objectStorageConfig.name }}
data:
storage: {{ index .Values $key | toYaml | b64enc }}
推荐阅读
- oracle - 表行计数验证 plsql
- c# - 类库的 Jaeger 配置
- oracle - 有没有办法在 dbms_xmlquery.getxml 或 DBMS_XMLGEN.getXML(..) 或其他 PL/SQL xml 函数中执行多个 sql 命令?
- javascript - 懒惰的 ReferenceError
- typescript - 打字稿中的相交键
- docker - dockerfile 中针对非 root 用户的 USER 指令的确切顺序
- node.js - 猫鼬allowDiskUse(真)不工作nodejs
- flutter - 全局侦听器小部件
- python - 如何在 Python 中从此 JSON 中获取“url”变量
- delphi - 如何将 popupparent 属性传递给 DLL