舵图错误无法评估类型接口{}中的字段值

时间:2019-06-19 15:40:18

标签: kubernetes kubernetes-helm

我知道这是某种与语法/ 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 }}为什么不起作用?我在其他地方使用了具有相同结构的值

3 个答案:

答案 0 :(得分:3)

不仅仅是范围问题吗?

尝试以下操作

{{- $fullName := include "mychart.fullname" . -}}
{{- $networkAppPort  := .Values.network.appPort -}}
...
.... omitted code
...
      http:
        paths:
        {{- range .paths }}
          - path: {{ . }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $networkAppPort }}
        {{- end }}
  {{- end }}

答案 1 :(得分:1)

我使用 helm3 并且在运行 helm template my-chart 时出现相同的错误消息。就我而言,我在 values.yaml,

中定义错误

错误的配置(在我的 values.yamlpath 缺少 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 }}

答案 2 :(得分:0)

对于YAML,还需要具有任何可选值的威吓父母。

就像您尝试在头盔构建过程中在某些Yaml中进行“ a.b.c”检查一样,它也会给出类似的错误。必须至少在默认值中添加a.b。yaml。

已通过-https://github.com/helm/helm/issues/5435

中的详细信息解决