Batch queues and workflow systems
Choose a Job or a queue
Batch work has a finite result: for example, calculating totals for three catalog partitions. A Kubernetes Job creates Pods until its completion policy is satisfied or it fails. A queue adds a separate admission decision so independent Jobs do not all compete for scarce resources immediately. Admission is not the same as Pod placement, container startup or successful output. Use a Job for independent bounded tasks; add a queue manager when teams share limited capacity or need admission policy.
Submit -> queue admission -> Pod scheduling -> execute -> verify outputRun a bounded indexed workload
An Indexed Job assigns a completion index to each partition. With three completions and parallelism two, the controller normally attempts at most two active Pods for the Job at once; replacements and termination can introduce temporary overlap. The following static manifest uses a deliberately invalid image reference. Its command reads JOB_COMPLETION_INDEX, sums ten integers and prints the index and total. The offline script executes the exact command locally for all three indexes. Expected outputs are 0 45, 1 145 and 2 245. The Job has a global retry budget, a deadline and a cleanup TTL; none guarantees exactly-once execution. For per-index retry controls check the selected Kubernetes version and API support separately.
apiVersion: batch/v1kind: Jobmetadata: name: catalog-shards namespace: bookstore-labspec: completions: 3 parallelism: 2 completionMode: Indexed backoffLimit: 2 activeDeadlineSeconds: 120 ttlSecondsAfterFinished: 600 template: spec: automountServiceAccountToken: false restartPolicy: Never securityContext: runAsNonRoot: true runAsUser: 10001 seccompProfile: type: RuntimeDefault containers: - name: shard image: registry.invalid/bookstore/python:fixture command: ["python3", "-c"] args: ["import os; i=int(os.environ['JOB_COMPLETION_INDEX']); print(i, sum(range(i*10, (i+1)*10)))"] resources: requests: {cpu: 100m, memory: 32Mi} limits: {cpu: 200m, memory: 64Mi} securityContext: allowPrivilegeEscalation: false capabilities: {drop: [ALL]}Reserve quota before placement
Kueue is an add-on, not an upstream Job field. A LocalQueue connects a namespace to a ClusterQueue; the latter defines quota associated with ResourceFlavors, which represent categories of capacity. The Workload abstraction carries the resource demand. Depending on configuration, admission can require quota reservation and other checks, and borrowing or preemption may apply. The actual kube-scheduler still places Pods. Consider a fictional strict FIFO queue with 4 CPU units, three jobs requesting 3, 2 and 1 units, and no borrowing. Admit A, hold B and C rather than skipping the head. Once A finishes, B and C can both reserve quota. This is the lab policy, not a universal Kueue ordering rule.
Capacity 4; A=3, B=2, C=1First pass: admit A; B and C waitAfter A releases 3: admit B and C; 1 unit remainsRetry safely and retain results
A retry after an interrupted write may repeat work that already succeeded. Use an output key based on the input revision and partition, and a durable conditional write or transaction for side effects. An identical result can be accepted again; conflicting content under the same key requires investigation. Separate transient failures from invalid input and stop at a configured limit. A completed Job is not evidence that a downstream report is correct. Save verified outputs before TTL cleanup and avoid treating the Pod filesystem as durable checkpoint storage.
output key: dataset-v1 / partition-2first value 245 -> commitretry value 245 -> already presentretry value 999 -> conflict; investigateCoordinate multi-stage data systems
A directed acyclic graph (DAG) describes task dependencies without cycles. Argo Workflows can execute such graphs, pass artifacts and apply retry rules; it is different from Argo CD. Spark uses driver and executor processes for distributed data tasks; Spark Kubernetes integration or an appropriate operator manages their lifecycle. Flink handles long-lived stateful processing, with external durable checkpoints and savepoints for recovery and controlled changes. These systems have their own APIs, permission and version requirements. Kubernetes does not automatically implement their data consistency, partition recovery or exactly-once sink guarantees.
extract -> validate -> transform -> publishvalidation fails: do not publishcheckpoint recovery: verify source offsets and sink behaviorPractice and next step
Read queue-cases.json, retry-cases.json and workflow-cases.json. Predict each outcome, then run python validate_offline.py in lab-fixtures/batch-ai. Explain why quota fit is not Pod fit, and why successful retries need an idempotency strategy. Next: AI workloads and data locality.
Offline model only; no Kueue, Spark, Flink or Argo controller installed.Further reading
- https://kubernetes.io/docs/concepts/workloads/controllers/job/ — Job completion, failure policy, bounded retries
- https://kueue.sigs.k8s.io/docs/concepts/admission/ — Quota reservation and admission
- https://kueue.sigs.k8s.io/docs/concepts/cluster_queue/ — Resource flavors, queue quota and borrowing
- https://kueue.sigs.k8s.io/docs/concepts/workload/ — Workload integration and LocalQueue
- https://argo-workflows.readthedocs.io/en/latest/ — Workflow dependencies and artifacts
- https://argo-workflows.readthedocs.io/en/latest/retries/ — Retry policy
- https://spark.apache.org/docs/latest/running-on-kubernetes — Spark driver and executor Pods
- https://nightlies.apache.org/flink/flink-kubernetes-operator-docs-stable/docs/managing/job-management/ — Flink stateful lifecycle and restore
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Batch queues and workflow systems — knowledge check
Compare scheduling and retry needs
What does queue admission establish?
What identifies a partition in an Indexed Job?
A strict FIFO queue has 4 units and A reserves 3. B needs 2 and C needs 1. What happens initially?
Why use a stable output key across retries?
Which system is designed for stateful stream processing?