yaml - 如何通过 CLI 覆盖 helm 环境变量?

标签 yaml environment-variables command-line-interface kubernetes-helm kubernetes-deployment

我正在使用 helm 环境变量来覆盖我的一些 spring boot application.yaml 配置,它工作得很好。

helm install deploy-name-1 mychartname --values=.helm/deployment/values.yaml

值.yaml

env:
  - name: WORD
    value: hello

在执行 helm install 命令时,我可以看到在 helm 部署期间选择了正确的 WORD,这一切都很好。

但是我想通过 CLI 上的 helm install 命令覆盖这个环境变量“WORD”的值。尝试时我遇到以下错误...

命令(取自 here ):

helm install deployment2 mychartname --values=.helm/deployment/values.yaml --set env.WORD=tree

错误

panic: interface conversion: interface {} is []interface {}, not map[string]interface {}

goroutine 1 [running]:
helm.sh/helm/v3/pkg/strvals.(*parser).key(0xc0004eff60, 0xc000538840, 0x1592d34, 0x1838b20)
        /home/circleci/helm.sh/helm/pkg/strvals/parser.go:211 +0xdf1
helm.sh/helm/v3/pkg/strvals.(*parser).parse(0xc0004eff60, 0xc000538840, 0x0)
        /home/circleci/helm.sh/helm/pkg/strvals/parser.go:133 +0x3f
helm.sh/helm/v3/pkg/strvals.ParseInto(0xc0000b60c0, 0x23, 0xc000538840, 0x0, 0x0)
        /home/circleci/helm.sh/helm/pkg/strvals/parser.go:70 +0xc5
helm.sh/helm/v3/pkg/cli/values.(*Options).MergeValues(0xc000080c60, 0xc0004efb40, 0x1, 0x1, 0x0, 0x0, 0x0)
        /home/circleci/helm.sh/helm/pkg/cli/values/options.go:62 +0x232
main.newUpgradeCmd.func1(0xc0001e0500, 0xc0004ffd80, 0x2, 0x8, 0x0, 0x0)
        /home/circleci/helm.sh/helm/cmd/helm/upgrade.go:82 +0x1fe
github.com/spf13/cobra.(*Command).execute(0xc0001e0500, 0xc0004ffc80, 0x8, 0x8, 0xc0001e0500, 0xc0004ffc80)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826 +0x467
github.com/spf13/cobra.(*Command).ExecuteC(0xc00069d180, 0x1c2f380, 0xc000676160, 0xc0004586d0)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x302
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main()
        /home/circleci/helm.sh/helm/cmd/helm/helm.go:74 +0x1e9

部署.yaml

...
    spec:
      containers:
        - name: {{ .Release.Name }}
          env:
            {{- range .Values.env }}
            - name: {{ .name }}
              value: {{ .value }}
            {{ end }}

最佳答案

helm install --set选项只允许基本的基于路径的导航,而不允许更高级的查询操作。不能用name: WORD查找env:值并设置相应的value:;您所能做的就是盲目地设置第一个 env: 值。

helm install ... --set 'env[0].value=tree'

与其通过 Helm 值提供整 block Kubernetes YAML,更常见的是提供非常具体的设置;提供“单词”作为配置,而不是“一组环境变量,其中应包括 WORD”。然后你可以直接覆盖这个特定的东西。

# templates/deployment.yaml
env:
  - name: WORD
    value: {{ .Values.word }}
# values.yaml
word: hello
helm install ... --set word=tree

关于yaml - 如何通过 CLI 覆盖 helm 环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68248917/

相关文章:

python - 动态指定选项和参数

c# - 未使用 c# 在 Windows 中设置环境。我哪里错了?

command-line - Mac Terminal-如何在CLI上启动Android Virtual Device Manager?

yaml - Jekyll:无法将 YAML 前端内容字段正确呈现为 Markdown

java - 从变量中获取变量列表

terminal - 如何将环境变量 PACKAGE_DIRS 链接到我的本地私有(private)包?

python - 如何从 python 脚本内部运行 python 命令?

php - C++ popen 运行 PHP

continuous-integration - TestCafe:测试不会通过 headless 模式

php - Behat 3 - 将参数(从导入的文件)传递给 FeatureContext 构造函数