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

Bra*_*avo 4 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
Run Code Online (Sandbox Code Playgroud)

值.yaml

env:
  - name: WORD
    value: hello
Run Code Online (Sandbox Code Playgroud)

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

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

命令(取自此处):

helm install deployment2 mychartname --values=.helm/deployment/values.yaml --set env.WORD=tree
Run Code Online (Sandbox Code Playgroud)

错误

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
Run Code Online (Sandbox Code Playgroud)

部署.yaml

...
    spec:
      containers:
        - name: {{ .Release.Name }}
          env:
            {{- range .Values.env }}
            - name: {{ .name }}
              value: {{ .value }}
            {{ end }}
Run Code Online (Sandbox Code Playgroud)

Dav*_*aze 8

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

helm install ... --set 'env[0].value=tree'
Run Code Online (Sandbox Code Playgroud)

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

# templates/deployment.yaml
env:
  - name: WORD
    value: {{ .Values.word }}
Run Code Online (Sandbox Code Playgroud)
# values.yaml
word: hello
Run Code Online (Sandbox Code Playgroud)
helm install ... --set word=tree
Run Code Online (Sandbox Code Playgroud)