0

I need to understand the behavior of kubernetes cronjob. New cronjob pod is started even when previous jobs is not completed. There is only one pod running against this job and previous pod has vanished. Why new job is started when first one is not completed. There is no trace of failure event by using kubectl describe job Userjob-1631434800

Command: 
kubectl get jobs

Output:
        NAME                                      COMPLETIONS   DURATION   AGE
        Userjob-1631434800                        0/1           25h        25h
        Userjob-1631496960                        0/1           8h         8h

Command:
kubectl get cronjobs

NAME                           SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
Userjob      */1 * * * *   False     1        8h              26h
Ali Ahmad
  • 1,055
  • 5
  • 27
  • 47

1 Answers1

0

You need to use concurrencyPolicy: Forbid. Using this cron job does not allow concurrent runs; if it is time for a new job run and the previous job run hasn’t finished yet, the cron job skips the new job run

Also you might checkout the other option

failedJobsHistoryLimit: 1 This will keep last 1 failed job.

successfulJobsHistoryLimit: 1 This will keep last 1 successful job. By default cronjob keeps 3 successful job pods.

Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42