CodeBlanks Logo Icon CodeBlanks

completions and parallelism

Learn Job completions and parallelism fields.

completions and parallelism

A Job also manages tasks that must run many times. completions sets how many successful pods are needed in total, and parallelism how many pods run at most at the same time:

spec:
  completions: 10     # 10 successful runs
  parallelism: 3      # at most 3 at once

$ kubectl get job isle
NAME   STATUS    COMPLETIONS   DURATION
isle   Running   4/10          40s

With completionMode: Indexed, each pod gets an ordinal from 0 to 9 in the JOB_COMPLETION_INDEX environment variable and processes its own part of the work.

Indexed jobs

An indexed Job is used to split big data into parts and process them in parallel. Each pod picks a file or range according to its index:

spec:
  completions: 5
  parallelism: 5
  completionMode: Indexed
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: isle
          image: busybox:1.36
          command: ["sh", "-c", "echo parca-$JOB_COMPLETION_INDEX isleniyor"]

Practice Parallel processing

Write a Job's spec section (starting with spec:): completions: 5, parallelism: 5, completionMode: Indexed; restartPolicy: Never in the template; container named isle, image busybox:1.36.

Starter code

terminal
# buraya yaz

Sample solution

terminal
spec:
  completions: 5
  parallelism: 5
  completionMode: Indexed
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: isle
          image: busybox:1.36

Expected output

job.batch/isle created
NAME   STATUS     COMPLETIONS   DURATION
isle   Complete   5/5           6s

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 With completions: 10, parallelism: 3, at least how many "waves" does the Job run?

  • 1
  • 4 Correct answer
  • 3
  • 10

Explanation: 3 + 3 + 3 + 1 = 10.

2 Run at most 3 pods at the same time.

Question
spec:
  completions: 10
  ____: 3
Answer
spec:
  completions: 10
  parallelism: 3

Explanation: parallelism is the concurrent pod limit.

3 Match.

Term Meaning
completions Required successes
parallelism Concurrent pods
Indexed Ordinal per pod
JOB_COMPLETION_INDEX Index variable

All lessons in Advanced