kubernetes - 变量值作为 helm 图表中的 yaml 键

标签 kubernetes kubernetes-helm go-templates

我想通过在 helm 命令行中设置变量来从 values.yaml 中选择配置部分。

values.yaml 的示例部分:

aaa:
  x1: "az1"
  x2: "az2"
bbb:
  x1: "bz1" 
  x2: "bz2"

configmap.yaml 的示例部分

data: 
  {{ .Values.outsideVal.x1 }}

预期的结果应该是这样的

   data:
     az1

测试 helm 输出

helm template --set outsideVal=aaa mychart

得到了这个错误

Error: render error in "./templates/configmap.yaml": template: ./templates/configmap.yaml:21:12: executing "./templates/configmap.yaml" at <.Values.outsideVal.x...>: can't evaluate field x1 in type interface {}

那么问题是如何得到预期的结果?

最佳答案

我怀疑您正在寻找 text/template index函数,可以通过变量key在map中查找值。

{{ (index .Values .Values.outsideVal).x1 }}

关于kubernetes - 变量值作为 helm 图表中的 yaml 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407940/

相关文章:

kubernetes - 为每个 namespace 定义值

kubernetes - 如何在 Kubernetes 中使用 Prometheus 和 AWS EBS?

javascript - 将结构数组传递给HTML模板以填充下拉列表

templates - 如何使用结构或变量值的字段作为模板名称?

Kubernetes 探测事件不可见但失败

kubernetes - 为什么新创建的ServiceAccount有0个 secret

azure - Azure Kubernetes (AKS) 'Time-out' 会发生什么情况会断开集群中 Pod 进出的连接?

kubernetes - 如何访问 3rd-party 自定义资源定义?

kubernetes - Helm 管理一组服务

go - 如何在{{define“…”}}的gotemplate中为&lt;input&gt;和<label>标签创建唯一的ID?