如何访问模板中自定义值.yaml文件中的值(HELM) [英] How to access values from a custom value.yaml files in templates (HELM)

查看:17
本文介绍了如何访问模板中自定义值.yaml文件中的值(HELM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问通过-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

推荐答案

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

.Values.secrets.postgres_admin_password

这篇关于如何访问模板中自定义值.yaml文件中的值(HELM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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