为每个命名空间定义值 [英] Define values for each namespace

查看:23
本文介绍了为每个命名空间定义值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

values.yaml

values.yaml

replicas: {
  test: 1,
  stage: 2,
  prod: 3
}

在这里,我尝试使用 Helm 模板来定义每个命名空间的副本数,但不确定正确的语法和模式:

Here I am trying to use Helm templates to define number of replicas per namespace but am unsure of the proper syntax and pattern:

deployment.yaml

deployment.yaml

replicas: {{ .Values.replicas.{{ .Release.Namespace }} }}

因此,如果将其部署到 --namespace=prod,我希望模板返回:

So if this were deployed to --namespace=prod, I would expect the template to return:

# .Values.replicas.prod
replicas: 3

推荐答案

Go 标准提供的所有模板功能 文本/模板 库可用.特别是,它包括一个 index 函数,它可以在数组或地图对象中进行动态查找.

All of the template functions provided by the standard Go text/template library are available. In particular, that includes an index function which can do dynamic lookup in an array or map object.

replicas: {{ index .Values.replicas .Release.Namespace }}

这篇关于为每个命名空间定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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