gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:41:07 27 4
gpt4 key购买 nike

我正在使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com