CKAD — Job Completions & Parallelism

2 minute read

Completions and Parallelism

By default, a Job creates one Pod and considers itself done when that Pod succeeds. But many real-world batch workloads need to process multiple items — either one at a time or in parallel.

Run Multiple Completions (Sequential)

If you need the Job to succeed a specific number of times:

apiVersion: batch/v1
kind: Job
metadata:
  name: sequential-job
spec:
  completions: 5
  template:
    spec:
      containers:
      - name: worker
        image: busybox:1.36
        command: ["/bin/sh", "-c", "echo Processing item && sleep 2"]
      restartPolicy: Never

This creates 5 Pods one after another. Each must complete successfully before the next starts.

kubectl apply -f sequential-job.yaml

# Watch Pods created one at a time
kubectl get pods -l job-name=sequential-job -w

# Check progress
kubectl get job sequential-job
# Expected: COMPLETIONS 5/5

Run in Parallel

Add parallelism to run multiple Pods at the same time:

apiVersion: batch/v1
kind: Job
metadata:
  name: parallel-job
spec:
  completions: 10
  parallelism: 3
  template:
    spec:
      containers:
      - name: worker
        image: busybox:1.36
        command: ["/bin/sh", "-c", "echo Processing item $JOB_COMPLETION_INDEX && sleep 3"]
      restartPolicy: Never

This runs up to 3 Pods at the same time until all 10 completions are done.

kubectl apply -f parallel-job.yaml

# Watch — you'll see 3 Pods running simultaneously
kubectl get pods -l job-name=parallel-job -w

# Check progress
kubectl get job parallel-job
# Expected: COMPLETIONS 10/10

How Completions and Parallelism Interact

completions parallelism Behavior
1 (default) 1 (default) One Pod runs, Job done when it succeeds
5 1 (default) 5 Pods run one at a time (sequential)
10 3 Up to 3 Pods run simultaneously until 10 succeed
10 10 All 10 Pods start at once (fully parallel)
Not set 3 3 Pods run; Job done when any one succeeds

Note: When completions is not set but parallelism is greater than 1, this creates a work queue pattern — the Job finishes when any Pod succeeds.

Job Completion Index

Kubernetes 1.24+ supports Indexed Jobs where each Pod gets a unique index:

apiVersion: batch/v1
kind: Job
metadata:
  name: indexed-job
spec:
  completions: 5
  parallelism: 5
  completionMode: Indexed
  template:
    spec:
      containers:
      - name: worker
        image: busybox:1.36
        command: ["/bin/sh", "-c"]
        args:
        - echo "I am worker $JOB_COMPLETION_INDEX"
      restartPolicy: Never

Each Pod receives the JOB_COMPLETION_INDEX environment variable (0, 1, 2, 3, 4). This is useful when each Pod needs to process a different partition of data.

Job Settings Summary

Field Description Default
completions Total successful Pod completions needed 1
parallelism Max Pods running simultaneously 1
completionMode NonIndexed (default) or Indexed NonIndexed
backoffLimit Max retries before marking Job as failed 6
activeDeadlineSeconds Max time (in seconds) for the entire Job None
ttlSecondsAfterFinished Auto-delete Job after this many seconds None

Exam tip: The CKAD exam frequently tests completions and parallelism. Remember: completions = how many total, parallelism = how many at once.


Next: Learn how to handle errors with Handling Job Failures →

Updated: