Review the Kubernetes CronJob start deadline

Choose the allowed start delay according to the job’s timing requirements.

Description

startingDeadlineSeconds sets how late the CronJob controller may create a Job after its scheduled time. Omit it if delayed runs are acceptable. The controller can still skip missed runs.

Potential impact

A late Job can act on stale data. A deadline shorter than routine controller delays can skip work that should run.

Remediation

  • Set spec.startingDeadlineSeconds to the longest useful delay, allowing for the controller’s check interval and operational delays.
  • Make the Job safe to repeat and review concurrencyPolicy and retries. To limit runtime after the Job starts, set the Job’s activeDeadlineSeconds.

Examples

Provide the job command and a verified image version. Adjust the sample deadline to suit the job.

Before

yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox
          restartPolicy: OnFailure

With no start deadline, a missed run can start after the controller recovers.

After

yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  startingDeadlineSeconds: 100
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox
          restartPolicy: OnFailure

The controller has up to 100 seconds after the scheduled time to create this Job.

References