Helm Error converting YAML to JSON: yaml: line 20: did not find expected key

问题描述 投票:0回答:3

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

部署.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
3个回答
9
投票

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

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

4
投票

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

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

 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.

0
投票

错误:无法解析 .mail-service-values.yaml:将 YAML 转换为 JSON 时出错:yaml:第 14 行:找不到预期的“:”

我在练习“Techworld with Nana”Bootcamp 中的一个用例时遇到了上述错误。就我而言,缩进是问题所在。当我提到超过 3 个散列 (---) 来分隔部署和服务相关键值时出现此错误。一旦我将哈希值减少到 3,问题

appName: emailservice
appReplicas: 2
appImage: gcr.io/google-samples/microservices-demo/emailservice
appVersion: v0.2.3
containerPort: 8080
containerEnvVars: 
- name: PORT
  value: "8080"
- name: DISABLE_TRACING
  value: "1"
- name: DISABLE_PROFILER
  value: "1"
---
servicePort: 5000
serviceType: ClusterIP
© www.soinside.com 2019 - 2024. All rights reserved.