2017-04-12 22:54:33 +00:00
---
2018-02-27 18:51:46 +00:00
reviewers:
2017-04-12 22:54:33 +00:00
- erictune
- soltysh
- janetkuo
2017-12-05 05:27:25 +00:00
title: CronJob
2017-04-12 22:54:33 +00:00
---
2018-05-05 16:00:51 +00:00
{{< toc > }}
2017-04-12 22:54:33 +00:00
## What is a cron job?
2018-01-25 16:58:16 +00:00
A _Cron Job_ manages time based [Jobs ](/docs/concepts/workloads/controllers/jobs-run-to-completion/ ), namely:
2017-04-12 22:54:33 +00:00
* Once at a specified point in time
* Repeatedly at a specified point in time
One CronJob object is like one line of a _crontab_ (cron table) file. It runs a job periodically
on a given schedule, written in [Cron ](https://en.wikipedia.org/wiki/Cron ) format.
2018-05-06 19:01:50 +00:00
For instructions on creating and working with cron jobs, and for an example of a spec file for a cron job, see [Running automated tasks with cron jobs ](/docs/tasks/job/automated-tasks-with-cron-jobs ).
2017-04-12 22:54:33 +00:00
## Cron Job Limitations
A cron job creates a job object _about_ once per execution time of its schedule. We say "about" because there
are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare,
but do not completely prevent them. Therefore, jobs should be _idempotent_ .
2017-12-24 04:39:15 +00:00
If `startingDeadlineSeconds` is set to a large value or left unset (the default)
2018-03-03 18:46:54 +00:00
and if `concurrencyPolicy` is set to `Allow` , the jobs will always run
2017-12-24 04:39:15 +00:00
at least once.
Jobs may fail to run if the CronJob controller is not running or broken for a
span of time from before the start time of the CronJob to start time plus
`startingDeadlineSeconds` , or if the span covers multiple start times and
`concurrencyPolicy` does not allow concurrency.
2018-05-06 19:01:50 +00:00
For example, suppose a cron job is set to start at exactly `08:30:00` and its
2017-12-24 04:39:15 +00:00
`startingDeadlineSeconds` is set to 10, if the CronJob controller happens to
be down from `08:29:00` to `08:42:00` , the job will not start.
Set a longer `startingDeadlineSeconds` if starting later is better than not
starting at all.
2018-01-19 03:24:14 +00:00
The Cronjob is only responsible for creating Jobs that match its schedule, and
2017-12-24 04:39:15 +00:00
the Job in turn is responsible for the management of the Pods it represents.