Jobs Basics
This section covers the Kubernetes Job object: how to run a container to completion, control retries and timeouts, and clean up after the work finishes.
Search across all documentation pages
This section covers the Kubernetes Job object: how to run a container to completion, control retries and timeouts, and clean up after the work finishes.
kubectl configured against it.kubectl version --client
kubectl get nodesThe smallest useful Job runs one Pod to completion.
apiVersion: batch/v1
kind: Job
metadata:
name: hello
spec:
template:
spec:
restartPolicy: Never
containers:
- name: hello
image: busybox:1.36
command: ["sh", "-c", "echo done && exit 0"]apiVersion: batch/v1 is the stable API for Jobs.restartPolicy to Never or OnFailure; Always is rejected.completions or parallelism, the Job succeeds after one Pod exits 0.kubectl apply -f job.yaml and watch with kubectl get job hello -w.Read the Job and its Pods to see progress and results.
kubectl get job hello
kubectl describe job hello
kubectl logs job/hellokubectl get job shows COMPLETIONS as succeeded over desired, like 1/1.kubectl logs job/hello streams logs from a Pod owned by the Job.describe surfaces events such as SuccessfulCreate and the final Completed condition.The restart policy changes how a failed attempt is retried.
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: worker
image: myrepo/worker:1.4.0Never creates a fresh Pod per attempt, so each try has its own logs.OnFailure restarts the container in the same Pod, creating fewer objects.Never when you want clean per-attempt debugging and event history.OnFailure when Pod churn or scheduling latency is a concern.Cap how many times a failing Job retries before it gives up.
spec:
backoffLimit: 4
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: myrepo/worker:1.4.0backoffLimit defaults to 6 if you omit it.Failed condition and stops.Put a hard wall-clock cap on the whole Job.
spec:
activeDeadlineSeconds: 600
backoffLimit: 4
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: myrepo/worker:1.4.0activeDeadlineSeconds counts from when the Job starts, across all retries.Failed with reason DeadlineExceeded.backoffLimit once the deadline passes.Delete finished Jobs and their Pods automatically.
spec:
ttlSecondsAfterFinished: 3600
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: myrepo/worker:1.4.0Batch Pods still need resource requests and a hardened security context.
spec:
template:
spec:
restartPolicy: Never
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
containers:
- name: worker
image: myrepo/worker:1.4.0
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
memory: "512Mi"requests drive scheduling and let the scheduler pack Pods onto nodes.memory limit prevents one batch Pod from starving co-tenants.runAsNonRoot plus RuntimeDefault seccomp aligns with the restricted Pod Security Standard.Run a fixed number of successful Pods, several at a time.
apiVersion: batch/v1
kind: Job
metadata:
name: batch-import
spec:
completions: 10
parallelism: 3
backoffLimit: 6
template:
spec:
restartPolicy: Never
containers:
- name: importer
image: myrepo/importer:2.1.0completions: 10 means the Job needs ten Pods to exit 0.parallelism: 3 runs up to three Pods concurrently.kubectl get job batch-import shows progress like 7/10.Create a Job without starting it, then release it later.
spec:
suspend: true
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: myrepo/worker:1.4.0suspend: true, no Pods are created until you flip it.kubectl patch job worker -p '{"spec":{"suspend":false}}'.React differently to specific container exit codes.
spec:
backoffLimit: 6
podFailurePolicy:
rules:
- action: FailJob
onExitCodes:
containerName: worker
operator: In
values: [42]
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: myrepo/worker:1.4.0podFailurePolicy lets you fail the whole Job fast on an unrecoverable exit code.FailJob instead of consuming retry budget.Ignore, which does not count a failure against backoffLimit.Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Reviewed by Chris St. John·Last updated Jul 16, 2026