An indexed Job runs a known number of tasks and gives each Pod a distinct completion index. The task uses that index to select its work, avoiding a separate database-backed queue. section 10.3 section 10.3.2
Configure an indexed Job around three decisions:
- Set completions to the total number of tasks, such as the number of frames to render. section 10.3.2
- Set completionMode to Indexed; each Pod receives JOB_COMPLETION_INDEX, which the application can use directly or to look up an item in a supplied task list. section 10.3.2
Listing 10.13 Chapter10/10.3.2_IndexedJob/indexed_job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: echo
spec:
completions: 5 #1
parallelism: 3 #2
completionMode: Indexed #3
template:
metadata:
labels:
pod: framerender
spec:
restartPolicy: Never
containers:
- name: 'worker'
image: 'docker.io/library/busybox'
command: ["echo", "render frame: $(JOB_COMPLETION_INDEX)"] #4
This configuration demonstrates five completions, three concurrent Pods, Indexed completion mode, and a worker command that prints its assigned frame number. section 10.3.2
Rendering numbered frames
For a 30,000-frame animation, set completions to 30,000. Kubernetes creates the task Pods and supplies indexes from the work list; each worker renders the frame matching its index. section 10.3.2
