我知道这是某种与语法/yaml 结构相关的错误,但该消息是如此神秘,我不知道问题是什么:
Error: render error in "mychart/templates/ingress.yaml": template: mychart/templates/ingress.yaml:35:37: executing "mychart/templates/ingress.yaml" at <.Values.network.appP...>: can't evaluate field Values in type interface {}
这是我的values.yaml:
network:
appPort: 4141
这是 ingress.yaml:
{{- $fullName := include "mychart.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "mychart.name" . }}
helm.sh/chart: {{ include "mychart.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ .Values.network.appPort }}
{{- end }}
{{- end }}
为什么
{{ .Values.network.appPort }}
不起作用?我在其他地方使用了具有相同结构的值
范围块中
.
指的是执行时间内的当前值。您可以使用 .
来访问范围块中的根数据对象,而不是声明顶级变量,而不是 $
。
示例:
{{- range $host := .Values.ingress.hosts }}
- host: {{ $host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: {{ $.Values.frontend.service.port }}
{{- end}}
这不只是范围问题吗?
尝试以下操作
{{- $fullName := include "mychart.fullname" . -}}
{{- $networkAppPort := .Values.network.appPort -}}
...
.... omitted code
...
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $networkAppPort }}
{{- end }}
{{- end }}
我使用 helm3,当我运行
helm template my-chart
时,我有相同的错误消息。就我而言,我在 values.yaml
, 中定义错误
错误的配置(在我的
values.yaml
中缺少path
下的paths
):
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
hosts:
- host: "dev"
paths:
- /dev(/|$)(.*)
tls: []
像这样更正入口定义,它可以工作
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
hosts:
- host:
paths:
- path: "/dev(/|$)(.*)"
tls: []
我的入口模板,
ingress.yaml
,它是通过 helm 自动生成的
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "bsb-lookup.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "bsb-lookup.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
对于 YAML,还需要具有任何可选值的直接父级。
就像您尝试在 helm 构建期间在某些 yaml 中检查“a.b.c”一样,它会给出类似的错误。默认值.yaml 中至少需要有 a.b。
通过详细信息解决 - https://github.com/helm/helm/issues/5435