Welcome to the Linux Foundation Forum!

Lab 6.3 - Error when trying to create cron job

sdalziel
sdalziel Posts: 17
edited April 2018 in LFS258 Class Forum

Hi all,

I'm working on "Exercise 6.3: Working with Cron Jobs". I have created the YAML file cron-job.yaml as shown below:


apiVersion: batch/v1beta1 kind: CronJob metadata: name: date spec: schedule: "*/1 * * * *" jobTemplate: spec: template: spec: containers: - name: dateperminute image: busybox args: - /bin/sh - -c - date; sleep 30 restartPolicy: OnFailure

When I attempt step 2. Create the cron job. I receive the error below.


~$ kubectl create -f cron-job.yaml error: error converting YAML to JSON: yaml: line 17: did not find expected key

Please advise what key I should be providing. 

Comments

  • serewicz
    serewicz Posts: 1,000
    edited April 2018

    Hello,

    Typically when you have this sort of error its because of whitespace indentation.  Often the error is actually on the preceeding line, but reports on the following line when there is an issue with that line.  In this case the very last line needs an extra whitespace to work.  If you get an error like this in the future, one idea is to use an online parser: https://www.json2yaml.com/ Replace the yaml on the right of the page and you'll see any errors.  Its also nice because you get immediate feedback as you work with the yaml. 

    For the pasting above I used the website and when I moved the restartpolicy on line 18 so it lined up with containers on line 11 the JSON become clear and looked like this:


    { "apiVersion": "batch/v1beta1", "kind": "CronJob", "metadata": { "name": "date" }, "spec": { "schedule": "*/1 * * * *", "jobTemplate": { "spec": { "template": { "spec": { "containers": [ { "name": "dateperminute", "image": "busybox", "args": [ "/bin/sh", "-c", "date; sleep 30" ] } ], "restartPolicy": "OnFailure" } } } } } }



    Regards,

  • sdalziel
    sdalziel Posts: 17

    Cheers! The website showed me the extra spaces.

    s.

Categories

Upcoming Training