CronJob Suspension and Deadlines
You'll learn how to pause CronJob execution temporarily and handle situations when scheduled jobs start late or miss their scheduled time.
Understanding CronJob Suspension
The suspend field in a CronJob spec acts like a pause button for your scheduled jobs. When set to true, Kubernetes stops creating new Job instances from the CronJob template, but leaves any already-running Jobs untouched.
Think of it like pausing your scheduled alarm clock: existing alarms that already went off continue ringing, but no new alarms will trigger until you un-pause.
apiVersion: batch/v1
kind: CronJob
metadata:
name: backup-job
spec:
schedule: "0 2 * * *"
suspend: true # Pauses scheduling
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: backup:latest
This is useful during maintenance windows, troubleshooting, or when you need to temporarily halt automated tasks without deleting the CronJob entirely.
Handling Missed Schedules with Deadlines
The startingDeadlineSeconds field defines how long Kubernetes should wait to start a missed job. If a scheduled execution is delayed (perhaps the cluster was down), this deadline determines whether the job should still run or be skipped.
spec:
schedule: "*/5 * * * *"
startingDeadlineSeconds: 300 # 5 minutes
If a job misses its 10:00 AM slot and doesn't start until 10:06 AM (6 minutes late), Kubernetes will skip it entirely because it exceeded the 5-minute deadline. Without this field, Kubernetes might queue up dozens of missed executions, overwhelming your cluster when it recovers.
Key Takeaway: Use suspend: true to temporarily pause CronJob scheduling without deletion, and set startingDeadlineSeconds to prevent late-starting jobs from piling up after outages or delays.