Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a Job that processes 50 work items with 5 running in parallel.

IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: batch/v1
kind: Job
metadata: { name: process-items }
spec:
  completions: 50
  parallelism: 5
  completionMode: Indexed
  backoffLimit: 6
  ttlSecondsAfterFinished: 3600
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: worker
          image: myrepo/worker:1.0
          command: ["python", "worker.py"]
          # each pod reads its index from the JOB_COMPLETION_INDEX env var

Key trick → completionMode: Indexed gives each pod a unique JOB_COMPLETION_INDEX (0–49), so you can shard work without a queue. ttlSecondsAfterFinished garbage-collects the finished Job.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks