Job
What is Job?
Job: Runs a Pod to completion — a batch task that should run once, succeed, and stop. Kubernetes retries it until the configured number of completions succeed. A Job in Kubernetes runs a task to completion: a pod starts, does its work and stops. If it fails, Kubernetes retries it up to a set limit, the backoffLimit.
Frequently asked questions about Job
How is Job used in practice?
Typical uses are database migrations, data imports, one-off fixes and batch processing. Unlike a Deployment, a Job is finished once it succeeds and is not restarted.
What should you keep in mind with Job?
Make Jobs safe to run more than once, because a retry after a timeout may repeat work that partly succeeded. Set ttlSecondsAfterFinished so finished Jobs and their pods are cleaned up automatically. For migrations, run the Job before the new application version starts serving traffic, for example as part of your deploy pipeline. For recurring tasks, use a CronJob, which creates Jobs on a schedule.
What does an example of Job look like?
apiVersion: batch/v1 kind: Job metadata: name: migrate spec: backoffLimit: 4 template: spec: restartPolicy: Never containers: - name: migrate image: myapp:1.0 command: ["./migrate.sh"] At a glance
| Category | Kubernetes |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |