Sobes.tech
Junior — Middle

What are the main differences between tasks scheduled with Job and CronJob in Kubernetes?

sobes.tech AI

Answer from AI

In Kubernetes, Job and CronJob are used to run tasks but have different use cases:

  • Job — runs a task once and monitors its successful completion. If the task fails, the Job can restart it (depending on settings). Used for one-time or ad-hoc tasks.

  • CronJob — is a scheduler that runs a Job on a schedule specified in cron format. It automates periodic tasks, such as daily backups or cleanup.

Example:

  • Job: Run a database migration once.
  • CronJob: Run a log cleanup script every day at 3 AM.

In summary, Job is for single execution, CronJob is for scheduled periodic execution.