Skip to content

Helm Template 错误

错误信息

                错误: template: chart/templates/部署.yaml: 错误 calling 包含
              

快速摘要

Helm Chart's Go templates 有语法错误, 引用 undefined 值, or produce 无效 YAML.

为什么发生

  • template 变量是 undefined or misspelled

  • Go template 语法错误 (missing {{ 端 }}, 错误函数 name)

  • 值.yaml 是 missing 必需值 那个 template 引用

  • rendered YAML 是无效 (错误 indentation, missing 字段)

最小示例

✗ 错误代码
# Template references undefined value
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
# values.yaml has no 'image' key
✓ 修复代码
# Add defaults in template
image: {{ .Values.image.repository | default "myapp" }}:{{ .Values.image.tag | default "latest" }}
# Or add to values.yaml:
# image:
#   repository: myapp
#   tag: "1.0"

template 引用 .值.镜像但 它是 不定义. fix 添加 defaults in template or 定义值.

如何诊断

  • 运行 helm template <chart> 到渲染 and see 错误

  • Use helm lint <chart> 到验证 chart

  • 检查 template file at 行 referenced in 错误

  • 验证所有必需值 是 provided in 值.yaml or 通过 --设置

如何修复

  • Fix Go template 语法 (添加 missing {{ 端 }}, 正确函数 names)

  • Provide missing 值 in 值.yaml or 通过 --设置

  • 添加默认值 in template: {{ .值.foo | 默认 "bar" }}

  • Fix rendered YAML 输出到 是有效 Kubernetes manifest

如何预防

  • 运行 helm lint in CI 之前 deploying

  • Use 默认值 in templates 到 avoid undefined 变量错误

  • 测试 charts 使用 helm template 之前 applying

相关资源

相关术语

← 返回语言