What Is a Kubernetes Job? Completion, retries, and parallel work
A Kubernetes Job manages Pods until a finite task completes successfully. Use it for work such as data conversion, one-time calculations, or batch processing. A Deployment manages services that should keep running. A Job retries failed work, but it does not guarantee that a program starts exactly once, so design tasks to tolerate retries and duplicate effects.
A Kubernetes Job manages Pods until a finite task completes successfully. Use it for work such as data conversion, one-time calculations, or batch processing. A Deployment manages services that should keep running. A Job retries failed work, but it does not guarantee that a program starts exactly once, so design tasks to tolerate retries and duplicate effects.
What counts as completion?
A simple Job completes after one Pod succeeds. By default, completions and parallelism are both 1. The Pod template may use only restartPolicy: Never or OnFailure. A fixed-count Job completes after .spec.completions Pods succeed; .spec.parallelism is the requested number of concurrent Pods and defaults to 1. Quotas, available resources, scheduling constraints, and prior failures can make actual concurrency lower.
If a Pod or node fails, the controller can create a replacement. backoffLimit controls how many failures are allowed before the Job is marked failed; its default is 6, with increasing delays between retries. With OnFailure, a container may restart inside its Pod. With Never, a failed Pod is replaced by another Pod. In either case, the same program can sometimes run more than once. Make side effects idempotent—for example, use a unique input key or completion record so retrying an item does not create duplicate output or charge twice.
Choosing a work pattern
| Pattern | Configuration and completion rule | Useful when |
|---|---|---|
| One task | Leave defaults; one successful Pod completes the Job | A migration, cleanup, or one-off calculation |
| Fixed completion count | Set completions; optionally set parallelism; finish after that many Pods succeed | Workers claim distinct items from a shared queue |
| Indexed Job | Fixed completions plus completionMode: Indexed; each Pod receives an index | Input can be divided into stable shards |
| Work queue | Omit completions, set parallelism, and coordinate through a queue | The item count is large or changes while work runs |
With a fixed completion count, the Pods share the same template. Kubernetes does not automatically assign a different file or record to each Pod. Use a queue, or let an Indexed Job map JOB_COMPLETION_INDEX to an input shard. Requested parallelism is not a promise: resource limits, quota, scheduling, and retries affect the number running. Concurrent workers must also avoid conflicting writes.
Example: process six input shards
This Indexed Job defines six logical tasks and requests at most two Pods at once. Each worker reads JOB_COMPLETION_INDEX to identify its shard. Replace the image and demonstration command with approved, application-specific values. The command below only prints an index; it does not transform data, and the manifest was not run in a cluster.
apiVersion: batch/v1
kind: Job
metadata:
name: shard-convert
namespace: batch
spec:
completions: 6
parallelism: 2
completionMode: Indexed
backoffLimit: 3
ttlSecondsAfterFinished: 86400
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: registry.example.com/team/converter:<approved-tag-or-digest>
command:
- python
- -c
- "import os; print('process shard', os.environ['JOB_COMPLETION_INDEX'])"The application must map each index to a stable input range. A node failure or kubelet restart can rarely cause overlapping Pods for the same index, so make shard output safe to retry, such as by writing to a unique key or using a completion lock. ttlSecondsAfterFinished schedules cleanup of the Job and dependent Pods after completion or failure. Choose a retention period long enough to inspect status and logs, and store logs separately if they must outlive the Pods.
Apply and verify
These commands are examples and were not run. Check permissions, namespace quota, node capacity, and image access before submitting the Job.
kubectl apply -f <job.yaml>
kubectl get jobs -n batch
kubectl get pods -n batch -l batch.kubernetes.io/job-name=shard-convert
kubectl describe job shard-convert -n batch
kubectl logs job/shard-convert -n batch
kubectl wait --for=condition=complete job/shard-convert -n batch --timeout=30mOn success, the Job reaches Complete; in this indexed example all six indexes should succeed. If COMPLETIONS is below the target, inspect Pod states and Job events. Pending can indicate resource, quota, or scheduling constraints; ImagePullBackOff suggests an image or registry-auth problem; repeated Failed or CrashLoopBackOff calls for exit-code, log, and configuration checks. Fix the cause before creating a replacement Job, preferably with a new name. Do not delete a failed Job before collecting evidence. Set a TTL only after allowing enough time for investigation; preserve logs independently when needed.
Job, CronJob, or Deployment?
A Job runs finite work once. A CronJob creates Jobs on a schedule, while each Job still manages its own Pods and retries. Scheduled creation is approximate, so scheduled work should also tolerate duplicate execution. A Deployment is for a service that should continue running; for a persistent worker, consider a Deployment consuming a queue rather than a Job.
Sources
[Kubernetes Job concepts and behavior](https://kubernetes.io/docs/concepts/workloads/controllers/job/)
[Job patterns for parallel processing](https://kubernetes.io/docs/tasks/job/)
[CronJob behavior and scheduling limits](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)
[Pod lifecycle and restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/)
[Job API fields](https://kubernetes.io/docs/reference/kubernetes-api/batch/job-v1/)
Scope: Job completion, retries, fixed-count and Indexed parallel tasks, operational checks, and selection among Job, CronJob, and Deployment. Official Kubernetes documentation reviewed on 2026-11-22. The manifest and commands are illustrative and were not executed. Database or queue transaction guarantees and application implementation are outside scope.