liveBook · Manning

Indexed completion mode

As explained in Kubernetes in Action, Second Edition

Indexed completion mode assigns each Job pod a distinct zero-based completion index that identifies the portion of work it should process.

Indexed completion mode gives every Job pod a distinct zero-based completion index. Pods use that index to process separate portions of one larger task instead of performing identical work. section 18.1.4

Configure indexed processing through the Job and its pod code:

  • Set spec.completionMode to Indexed and choose the total number of indexes with spec.completions. section 18.1.4
  • Read the index from JOB_COMPLETION_INDEX or from the batch.kubernetes.io/job-completion-index pod annotation. section 18.1.4
  • Treat each index as a work partition; a failed pod is replaced with another pod carrying the same index. section 18.1.4
  • Use a headless Service and set the pod template's subdomain when indexed pods must address one another through DNS. section 18.1.6

Assigning one month to each pod

A Job with completionMode: Indexed and completions: 12 can process twelve months independently. Its script reads JOB_COMPLETION_INDEX, adds one, and uses the result as MONTH; parallelism: 3 runs three partitions at once. section 18.1.4

Giving indexed pods stable DNS names

Set completionMode to Indexed, create a headless Service with clusterIP: None, and use the Service name as the pod template's subdomain. Pods can then resolve names such as comm-demo-0.demo-service. section 18.1.6

Table 18.2 Supported Job completion modes
Value
Description
NonIndexed
The Job is considered complete when the number of successfully completed pods created by this Job equals the value of the spec.completions field in the Job manifest. All pods are equal. This is the default mode.
Indexed
Each pod is given a completion index (starting at 0) to distinguish the pods from each other. By default, the Job is considered complete when there is one successfully completed pod for each index. If a pod with a particular index fails, the Job controller creates a new pod with the same index. You can also change the default success policy so that the Job counts as successful when pods with specific indexes complete successfully.
The completion index assigned to each pod is specified in the pod annotation batch.kubernetes.io/job-completion-index and in the JOB_COMPLETION_INDEX environment variable in the pod’s containers.

Compare Indexed with the default NonIndexed mode, including completion criteria, pod identity, retry behavior, and success policies. section 18.1.4

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains configuration, index retrieval, retries, success criteria, and DNS communication, but defers controller implementation details.
Examples
Demonstrates monthly response aggregation and indexed pod-to-pod communication through a headless Service.
What it assumes
Assumes basic familiarity with Jobs and pod templates while introducing Indexed versus NonIndexed completion behavior.
What you can do after
Configure Kubernetes Jobs that divide work across indexed pods and expose their indexes to application code.
How it connects
Connects Jobs with Pods, pod annotations, environment variables, ConfigMaps, headless Services, and DNS.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.