What's the difference between a Job and a CronJob?
Quick Answer
A Job runs a pod (or several) to successful completion once — for batch work, migrations, or one-off tasks. A CronJob creates Jobs on a time schedule, like cron for the cluster.
Detailed Answer
A Job ensures a task runs to completion: it starts pods, retries on failure up to backoffLimit, and can run multiple completions in parallel (completions/parallelism) for batch processing. Unlike a Deployment, a Job's pods are meant to finish, not run forever. A CronJob wraps Jobs with a cron schedule, spawning a new Job each interval — nightly reports, backups, cleanup. Important knobs: concurrencyPolicy (Allow/Forbid/Replace) decides what happens if the previous run is still going; startingDeadlineSeconds bounds how late a missed run may start; successfulJobsHistoryLimit/failedJobsHistoryLimit control how many finished Jobs are retained. Watch for pitfalls: a Job that never succeeds retries until backoffLimit then fails; CronJobs use the controller's timezone unless you set spec.timeZone; and long-running Jobs overlapping with Forbid/Replace policies can surprise you.
Code Example
apiVersion: batch/v1
kind: CronJob
metadata: { name: nightly-backup }
spec:
schedule: "0 2 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 3
template:
spec:
restartPolicy: Never
containers: [{ name: backup, image: backup-tool }]Interview Tip
Job = run to completion; CronJob = scheduled Jobs. Name the gotchas — concurrencyPolicy, timeZone, and history limits — to show you've operated them, not just read the docs.