我正在构建一个新的 Helm 图表 (mychart),并尝试安装。
存在 values.yaml
且其内容指定 fullnameOverride:
fullnameOverride: "myapp"
我运行以下命令
helm install --dry-run -f "mychart-stack/values.yaml"mychart-stack1 ./mychart-stack
它给了我错误:
template: mychart-stack/templates/persistentvolume.local-storage.range.yml:5:14: executing "mychart-stack/templates/persistentvolume.local-storage.range.yml" at <include "mychart-stack.fullname" .>: error calling include: template: mychart-stack/templates/_helpers.tpl:14:14: executing "mychart-stack.fullname" at <.Values.fullnameOverride>: nil pointer evaluating interface {}.fullnameOverride
mychart-stack/templates/_helpers.tpl:14:14
是当您要求 Helm 生成图表示例时预先生成的。
错误 (14:14) 与以下自动生成的代码的第一行相关联:
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
更多上下文,因为它在检查 permanentvolume.local-storage.range.yml 时抛出错误,以下是文件的内容:
{{- range .Values.persistentVolume.localStorage }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-{{ include "mychart-stack.fullname" }}-{{ .name }}
spec:
capacity:
storage: 20Gi
# le champ volumeMode requiert l'activation de la "feature gate" Alpha BlockVolume
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage-{{ include "mychart-stack.fullname" }}--{{ .name }}
local:
path: {{ .Values.persistentVolume.basePath }}/{{ .name }}
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ .Values.hostName }}
{{- end }}
我不知道出了什么问题,代码似乎表明它没有正确定义。 我尝试在 --debug 模式下运行它,但它没有帮助(相同的错误)。
最佳答案
最后,问题不在于values.yaml设置不正确,而更多在于它在模板中的使用方式。
当使用来自 .tpl 文件的定义的包含(这是由 Helm 自动生成的)时,我们必须小心不要在范围内。
我正在创建一系列 Assets ,因此它似乎会在该范围的上下文中运行代码。
Your conditional logic is being evaluated inside a range loop. This means . you're using to access Values is not the one you expect it to be, as it's overridden for each range iteration evaluation.
引用:ingress.yaml template returns error in renderring --> nil pointer evaluating interface {}.service
这意味着我们应该使用 $
而不是 .
表示法,因为它引用全局范围。
示例:
{{- include "mychart-stack.fullname" $ }}
关于kubernetes - 如何修复 Helm "installation failed"提示 fullnameOverride 上的 nil 指针评估接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75544858/