如何解决如何从模板HELM中的自定义value.yaml文件访问值
我正在尝试访问密钥-来自自定义值文件secretvalues.yaml
的值,该文件通过-f
参数传递给掌舵。此文件中的键-值将传递到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
values.yaml
文件夹中postgres-services/
文件的内容是
config:
postgres_admin_name: "postgres"
secretvalues.yaml
文件夹中k8shelmchars/
文件的内容是
secrets:
postgres_admin_password: "password"
,postgres.configmap.yml
文件夹中postgres-services/
文件的内容为
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
谢谢!
尝试通过使用secretvalues.yaml
中的POSTGRES_PASSWORD: {{ .Values.config.postgres_admin_password }}
从postgres.configmap.yml
文件访问键值似乎会拉空值/无值。
运行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:
表明头盔无法从secretvalues.yaml
文件中提取值。注意:我已将secrets
文件中的密钥从config
更新为secretvalues.yaml
。
解决方法
所有文件中的值都合并到一个对象Values
中,因此您应该像访问其他对象一样,从secretvalues.yaml
访问变量,即
.Values.secrets.postgres_admin_password
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。