✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes CronJob Suspension Management

Kubernetes CronJob Suspension Management explains how to pause and resume scheduled jobs for better resource control in Kubernetes.

Kubernetes CronJob Suspension Management is the practice of temporarily halting new scheduled executions of a batch/v1 CronJob without deleting or otherwise losing its configuration, using the .spec.suspend boolean field. Suspension is a reversible, non-destructive pause: it stops the CronJob controller from creating any new Jobs at future scheduled ticks, while leaving the CronJob object, its schedule, its job template, and its execution history completely intact, ready to resume exactly where it left off once unsuspended.

This distinguishes suspension from deletion or from patching away the schedule: a suspended CronJob remains a first-class, inspectable object in the cluster the entire time it is paused, which is what makes it suitable for planned maintenance windows, incident response, and controlled rollouts of workload changes.


Behavior of suspend

Setting Suspend

spec:
  suspend: true
kubectl patch cronjob codartium-nightly-report -p '{"spec":{"suspend":true}}'

Once applied, the CronJob controller stops evaluating the schedule for that object entirely — it will not create new Jobs at any subsequent scheduled tick, and any ticks that occur while suspended are treated the same as missed schedules once the CronJob is later resumed, subject to startingDeadlineSeconds.

Existing Jobs Are Unaffected

Suspension does not touch any Jobs already created before the CronJob was suspended. A run already in progress at the moment suspend is set to true continues running to completion (or failure) exactly as it would have otherwise; suspension only prevents new Jobs from being created going forward.

Resuming

kubectl patch cronjob codartium-nightly-report -p '{"spec":{"suspend":false}}'

Setting suspend back to false allows the CronJob controller to resume evaluating the schedule normally. Whether ticks that occurred during the suspension window are caught up depends on startingDeadlineSeconds, exactly as with any other period of controller inactivity.


Operational Use Cases

Planned Maintenance Windows

Suspending CronJobs whose workloads write to a database or external system before performing planned maintenance on that dependency (a schema migration, a maintenance window on a downstream API) avoids scheduled runs failing repeatedly or, worse, partially succeeding against a system in an inconsistent intermediate state.

Incident Response

During an active incident, suspending non-critical recurring workloads is a common way to reduce load on a struggling cluster or shared dependency without needing to identify and delete each CronJob individually, since suspension is easily reversible once the incident is resolved.

Controlled Rollout of Configuration Changes

Suspending a CronJob, applying a change to its job template, and then manually triggering a single test run via kubectl create job --from=cronjob/... before resuming the schedule is a safer pattern for validating changes than allowing the next scheduled tick to apply the new configuration automatically and potentially fail at an inconvenient time.

Environment-Specific Defaults

Non-production environments (staging, ephemeral preview environments) often deploy CronJobs with suspend: true set by default in their base configuration, only enabling the schedule in environments where the recurring workload is actually desired, avoiding unnecessary resource consumption or unwanted side effects (like sending real notifications) from staging environments.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: codartium-nightly-report
spec:
  schedule: "0 2 * * *"
  suspend: true   # overridden to false only in the production overlay
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: report
              image: codartium/report-generator:latest

Verifying Suspension State

kubectl get cronjob codartium-nightly-report -o jsonpath='{.spec.suspend}'
kubectl get cronjobs -o custom-columns=NAME:.metadata.name,SUSPEND:.spec.suspend,SCHEDULE:.spec.schedule

A cluster-wide audit query listing every CronJob's suspend state alongside its schedule is a useful pre-maintenance checklist item, confirming that all CronJobs intended to be paused for an upcoming window have actually had suspend applied before the maintenance begins.