A CronJob creates Jobs on a recurring schedule. Use it for repeatable batch work such as daily cleanup, without requiring developers to remember a complex manual command. section 10.2.2 section 10.5
Its structure is nested: the CronJob contains a Job template, and that Job contains a Pod template. This composition lets the scheduled workload use Job and Pod fields while Kubernetes creates ordinary Pods from the templates. section 10.2.2
Choose the workload type according to how the background work should run:
- Use a Deployment for a continuously running task queue, commonly coordinated with a queue such as Redis. section 10.5
- Use a Job for one-off work, static-queue processing, or batch work that terminates when complete. section 10.5
- Use a CronJob when Kubernetes should create those Jobs at recurring intervals. section 10.2.2 section 10.5
Run a worker every five minutes
Define a CronJob named addwork with schedule "*/5 * * * *". Its Job template runs the pi_worker:2 image with add_tasks.py, passes REDIS_HOST and PYTHONUNBUFFERED environment variables, and uses restartPolicy: Never. After creation, kubectl get cronjob,job,pods shows the scheduled Job and a Completed Pod.

