【问题标题】:Helm Error converting YAML to JSON: yaml: line 20: did not find expected key将 YAML 转换为 JSON 时出现 Helm 错误:yaml:第 20 行:未找到预期的密钥
【发布时间】:2021-03-09 21:31:37
【问题描述】:

我真的不知道这里的错误是什么,是一个带有 _helpers.tpl 的简单 helm deploy,它没有意义,可能是一个愚蠢的错误,代码:

部署.yaml

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
{{ include "metadata.name" . }}-deploy
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        vars: {{- include "envs.var" .Values.secret.data }}

_helpers.tpl

{{- define "envs.var"}}
{{- range $key := . }}
- name: {{ $key | upper | quote}}
  valueFrom:
    secretKeyRef:
      key: {{ $key | lower }}
      name: {{ $key }}-auth
{{- end }}
{{- end }}

values.yaml

secret:
  data:
    username: root
    password: test

错误

Error: YAML parse error on mychart/templates/deploy.yaml: error converting YAML to JSON: yaml: line 21: did not find expected key

【问题讨论】:

  • 您能否确认下面提供的解决方案是否适合您?

标签: kubernetes kubernetes-helm go-templates


【解决方案1】:

这里出现这个问题是因为缩进。可以通过更新解决

env: {{- include "envs.var" .Values.secret.data | nindent 12  }}

【讨论】:

  • 我不敢相信这个错误和用错词一样愚蠢,我想我真的筋疲力尽了,最近修好了,然后想起了这个问题,无论如何谢谢你的帮助
【解决方案2】:

解决此类问题的最简单方法是使用工具。

这些大多是缩进问题,使用正确的工具可以很容易地解决

 npm install -g yaml-lint

yaml-lint 就是这样一种工具

 PS E:\vsc-workspaces\grafana-1> yamllint .\grafana.yaml
× YAML Lint failed for C:/Users/mnadeem6/vsc-workspaces/grafana-1/grafana.yaml
× bad indentation of a mapping entry at line 137, column 11:
          restartPolicy: Always
          ^
PS E:\vsc-workspaces\grafana-1> yamllint .\grafana.yaml
√ YAML Lint successful.

【讨论】:

    猜你喜欢
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 2020-03-10
    • 2019-12-13
    • 2019-06-26
    相关资源
    最近更新 更多