Creating Jobs
Job provide different ways to define tasks that run to completion and then stop. You can use a Job to define a task that runs to completion, just once.
- Atomic Execution Unit: Each Job manages one or more Pods until successful completion.
- Retry Mechanism: Controlled by
spec.backoffLimit
(default: 6).
- Completion Tracking: Use
spec.completions
to define required success count.
Example
apiVersion: batch/v1
kind: Job
metadata:
name: data-processing-job
spec:
completions: 1 # Number of successful completions required
parallelism: 1 # Maximum parallel Pods
backoffLimit: 3 # Maximum retry attempts
template:
spec:
restartPolicy: Never # Job-specific policy (Never/OnFailure)
containers:
- name: processor
image: alpine:3.14
command: ["/bin/sh", "-c"]
args:
- echo "Processing data..."; sleep 30; echo "Job completed"
Execution Overview
Each Job execution in Kubernetes creates a dedicated Job object, enabling users to:
- Track job lifecycle through
kubectl get jobs
- Inspect execution details via
kubectl describe job/<job-name>
- View Pod logs using
kubectl logs <pod-name>