error converting YAML to JSON: yaml: line 16: mapping values are not allowed in this context

7/18/2019

I am trying to create a Kubernetes cronjob. During the deployment, I get this error:

Error: UPGRADE FAILED: YAML parse error on lemming-metrics/templates/lemming-metrics-cronjob.yaml: error converting YAML to JSON: yaml: line 16: mapping values are not allowed in this context

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ .Values.name }}
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: {{ .Values.lemming_metrics.kubeServiceAccount }}
          containers:
          - name: {{ .Values.name }}
            image: {{ .Values.image.repository }}
            tag: latest
            imagePullPolicy: Always
            resources: {{ toYaml .Values.resources }}
            args:
            - /usr/bin/python
            - /opt/lemming_metrics.py
            env:
            - name: REGIONS
              value: {{ .Values.lemming_metrics.regions}}
            - name: ECS_CLUSTER
              value: {{ .Values.lemming_metrics.ecs_cluster}}
          restartPolicy: OnFailure
    backoffLimit: 2
    activeDeadlineSeconds: 90

Thanks for any help in advance

-- Suresh Ravi
kubernetes
yaml

1 Answer

3/23/2020

Looks like you might need to fix the spacing for the indents (use 2 spaces). Otherwise, I've found that if you are incorrectly defining a service/pod/deployment, you can receive this error message (where specific line it points to in reality doesn't matter)

-- user1394
Source: StackOverflow