Back to Glossary
Workloads

CronJob

A controller that creates Jobs on a repeating schedule defined by a cron expression.

What is CronJob?

A CronJob is a Kubernetes controller that periodically creates Job objects on a schedule expressed in standard cron format (e.g., '0 * * * *' for hourly). Each triggered execution spawns a new Job, which in turn creates one or more Pods. CronJobs are used for scheduled tasks: nightly backups, hourly cache invalidation, daily report emails, and periodic cleanup routines.

CronJob behavior is configurable via several key fields: concurrencyPolicy (Allow, Forbid, or Replace) controls what happens if a previous Job is still running when a new one is triggered; startingDeadlineSeconds sets how long after the scheduled time a Job can still be created if the scheduler missed the window; successfulJobsHistoryLimit and failedJobsHistoryLimit control how many completed Job records are retained (defaults are 3 and 1 respectively).

CronJobs are suspended by setting spec.suspend: true, which prevents new Jobs from being created without deleting the CronJob object itself. This is useful for temporarily halting scheduled tasks during maintenance windows or debugging.

Example

apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly-backup
  namespace: production
spec:
  schedule: "0 2 * * *"   # 2:00 AM daily
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
          - name: backup
            image: my-org/backup-tool:latest
            resources:
              requests:
                cpu: "200m"
                memory: "128Mi"

Cost & Waste Implications

CronJobs with high successfulJobsHistoryLimit values accumulate old Job and Pod objects at a rate proportional to their schedule frequency. A CronJob running every minute with a history limit of 100 keeps 100 completed Jobs at all times. More critically, CronJobs with missing resource requests can burst node CPU/memory at scheduled times, causing node pressure and evictions of production Pods.

KorPro— Kubernetes Cost Optimization

How KorPro Helps

KorPro identifies CronJobs with accumulating Job history and flags CronJobs that have been suspended for extended periods but are still holding historical Job records and associated storage.

Scan Your Cluster Free

Stop Wasting Money on Orphaned Kubernetes Resources

KorPro connects to your clusters across GCP, AWS, and Azure — no agents, no installation — and surfaces every orphaned resource with its monthly cost estimate.