2
votes

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

1
Sees like you have copied this directly from a Helm template. Try starting with a sample cron job from Kubernetes docs. Helm templates have placeholders (all those {....} strings for example) which get replaced before deployment. This is not valid yaml til placeholders get replaced.user6317694
As @user6317694 mentioned values in {} will be mapped with values from other file. Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. If you want to use helm you have to use it proper. Please check Helm guide. If you want to apply it using kubectl you have to write cronjob from documenation. Please provide more information if you are using HELMPjoterS

1 Answers

2
votes

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)