【问题标题】:How to access values from a custom value.yaml files in templates (HELM)如何从模板中的自定义 value.yaml 文件访问值(HELM)
【发布时间】:2020-09-29 22:26:32
【问题描述】:

我正在尝试访问使用 -f 参数传递给 helm 的自定义值文件 secretvalues.yaml 中的键值。此文件中的键值正在传递到 yaml 文件 postgres.configmap.yml

这是我的文件夹结构(还有一些其他图表,但为简单起见,我已将其删除)

├── k8shelmcharts
│   ├── Chart.yaml
│   ├── charts
│   │   ├── postgres-service
│   │   │   ├── Chart.yaml
│   │   │   ├── templates
│   │   │   │   ├── postgres.configmap.yml
│   │   │   │   ├── postgres.deployment.yml
│   │   │   │   └── postgres.service.yml
│   │   │   └── values.yaml
│   └── secretvalues.yaml

postgres-services/文件夹中values.yaml文件的内容是

config:
  postgres_admin_name: "postgres"

k8shelmchars/文件夹中secretvalues.yaml文件的内容是

secrets:
  postgres_admin_password: "password"

postgres-services/文件夹中postgres.configmap.yml文件的内容是

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
data:
  # property-like keys; each key maps to a simple value
  POSTGRES_USER: {{ .Values.config.postgres_admin_name }}
  POSTGRES_PASSWORD: {{ .secretvalues.secrets.postgres_admin_password }}

我在这里尝试了几种组合,例如.secretvalues.secrets.postgres_admin_password.Secretvalues.secrets.postgres_admin_password,并尝试删除secrets 键但无济于事。

当我运行命令安装图表时helm install -f k8shelmcharts/secretvalues.yaml testapp k8shelmcharts/ --dry-run --debug 我得到了错误:

Error: template: flask-k8s-app/charts/postgresdb/templates/postgres.configmap.yml:8:37: executing "flask-k8s-app/charts/postgresdb/templates/postgres.configmap.yml" at <.secretvalues.parameters.postgres_admin_password>: nil pointer evaluating interface {}.parameters
helm.go:94: [debug] template: flask-k8s-app/charts/postgresdb/templates/postgres.configmap.yml:8:37: executing "flask-k8s-app/charts/postgresdb/templates/postgres.configmap.yml" at <.secretvalues.parameters.postgres_admin_password>: nil pointer evaluating interface {}.parameters

我的问题是如何访问secret.postgres_admin_password

我正在使用helm3

谢谢!


尝试通过在postgres.configmap.yml 中使用POSTGRES_PASSWORD: {{ .Values.config.postgres_admin_password }} 来访问secretvalues.yaml 文件中的键值似乎会拉取null/nil 值。

我在运行 helm install testapp k8shelmcharts/ --dry-run --debug -f k8shelmcharts/secretvalues.yaml 时遇到错误:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: unknown object type "nil" in ConfigMap.data.POSTGRES_PASSWORD
helm.go:94: [debug] error validating "": error validating data: unknown object type "nil" in ConfigMap.data.POSTGRES_PASSWORD

当我尝试使用helm template k8shelmcharts/ --debug 调试模板时,我看到了:

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
data:
  # property-like keys; each key maps to a simple value
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD:         

表示 helm 无法从 secretvalues.yaml 文件中提取值。注意:我已将 secretvalues.yaml 文件中的密钥从 secrets 更新为 config

【问题讨论】:

    标签: kubernetes yaml kubernetes-helm


    【解决方案1】:

    所有文件的值都合并到一个对象Values,因此您应该像访问其他文件一样访问secretvalues.yaml 中的变量,即

    .Values.secrets.postgres_admin_password
    

    【讨论】:

    • @WytrzymałyWiktor 不完全是,它现在抛出了一个不同的错误。我已经根据我的观察更新了这个问题。
    猜你喜欢
    • 2020-07-20
    • 1970-01-01
    • 2012-03-25
    • 2019-10-28
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多