liveBook · Manning

Indexed job

As explained in Kubernetes for Developers

An indexed Job is a Kubernetes Job whose task instances are identified by distinct completion indexes assigned to its Pods.

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

How Kubernetes for Developers covers it

How deep it goes
Explains configuration, index delivery, task lookup, and observed output, but does not detail worker implementation.
Examples
Demonstrates rendering animation frames and printing indexes from a BusyBox worker.
What you can do after
Operate/configure an Indexed Job that assigns numbered tasks to worker Pods.
How it connects
Connects Jobs with Pods, static work queues, parallelism, environment variables, and init containers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.