The completion index is pod metadata assigned by the Job controller when a Job uses Indexed completion mode. Starting at 0, it distinguishes pods processing separate portions of a dataset. section 18.1.4
The annotation key is batch.kubernetes.io/job-completion-index. Workloads can read its value directly or expose it as an environment variable through a pod field reference. section 18.1.4
The index supports indexed batch processing by:
- Giving each pod a stable position within the Job, while failed pods are replaced with a pod carrying the same index. section 18.1.4
- Letting application code select its work from the index; a zero-based value of 0 can represent the first month after adding 1. section 18.1.4
- Separating pod identity from parallelism: completions sets the number of indexes, while parallelism limits simultaneous pods. section 18.1.4
Expose the annotation to a container
env: - name: MONTH valueFrom: fieldRef: fieldPath: metadata.annotations['batch.kubernetes.io/job-completion-index'] section 18.1.4
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 and NonIndexed completion modes to see why the annotation exists and how Job completion is counted. section 18.1.4
