Kubernetes

What issue might arise from using the following CronJob and how to fix it?

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: "some-cron-job"
spec:
  schedule: '*/1 * * * *'
jobTemplate:
  spec:
    template:
      spec:
      restartPolicy: Never
      concurrencyPolicy: Forbid
      successfulJobsHistoryLimit: 1
      failedJobsHistoryLimit: 1

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

The following lines placed under the template:

concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1

As a result this configuration isn't part of the cron job spec hence the cron job has no limits which can cause issues like OOM and potentially lead to API server being down.

To fix it, these lines should placed in the spec of the cron job, above or under the "schedule" directive in the above example.