CronJobs

CronJobs are Jobs with schedules. Schedules are expressed in the same time format as the traditional Unix cron daemon. It's suited to the same periodic workloads such as scheduled tasks.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
    name: my-cron
spec:
    schedule: "*/30 * * * *"
    jobTemplate:
        spec:
            template:
                containers:
                  - name:
                          image:
                          command:
                            - /something
                          restartPolicy: Never

Execution control

Some additional features allow more precise control over execution:

  • suspend can be use to stop future executions.
  • startingDeadlineSeconds sets the amount of time to wait for a Job to start before considering this execution failed.
  • concurrencyPolicy sets the action to be taken when a new execution begins during an existing one:
    • Allow lets both run.
    • Forbid prevents the new execution.
    • Replace terminates the existing job and creates a new one.
  • Up to successfulJobHistoryLimit objects are preserved to allow troubleshooting.

Implementation

The CronJob controller creates a Job object for each execution.