Job Parallelism and Completions

A Job needs 5 successful completions, runs up to 3 Pods at a time, and one Pod fails. How does the Job still reach the finish, what does that one failure change for the Pods it creates next, and when would it give up?

Play the animation 5 steps, animated, plays on a computer or a tablet

Job Parallelism and Completions, Kubernetes diagram

Job Parallelism and Completions, step by step

  1. A Job with a fixed completion count runs Pods until that many of them succeed. This one asks for 5 successful runs and allows 3 at once, so the controller sees 0 Pods running against a parallelism of 3 and creates 3 from one Pod template. Nothing has finished yet, so no completion is recorded and .status.active is 3.

    Play from step 1
  2. Two runs, resize-images-x7k2p and resize-images-m4qbz, finish cleanly with exit code 0. A successful Pod run counts once toward .spec.completions, so .status.succeeded moves from 0 to 2. A Pod that has succeeded is never restarted or reused, so the Job creates a new one for the next completion.

    Play from step 2
  3. At the same time the third run, resize-images-t9dhw, fails with exit 1. Under restartPolicy Never such a Pod reaches phase Failed, so .status.failed increments, no completion is recorded, and the failure counts against .spec.backoffLimit, 6 by default. The Pod object is not deleted, so its logs and exit code stay readable.

    Play from step 3
  4. Three completions are still owed and no Pod is running, so the controller creates 3 new Pods, up to the parallelism cap again. The failure delayed all three, not only the retry. The back-off after one failure since the last success is 10s, then 20s, 40s and on, capped at ten minutes.

    Play from step 4
  5. The last three Pods exit 0, and .status.succeeded reaches 5, which equals .spec.completions. The controller stops creating Pods and records the condition Complete=True. The one earlier failure stays counted, and the Job and its Pods stay until deleted, or until ttlSecondsAfterFinished runs out if set.

    Play from step 5

Sources