Batch Jobs & Indexed Workflows
Kubernetes Job resources run a task to completion, automatically handling node failures and retries.
Standard Batch Job Manifest
Section titled “Standard Batch Job Manifest”Create batch-simulation.yaml:
apiVersion: batch/v1kind: Jobmetadata: name: lbnl-diffraction-sweep namespace: sci-myprojectspec: backoffLimit: 3 # Retry up to 3 times if task exits with non-zero status activeDeadlineSeconds: 86400 # 24 hours max runtime template: spec: restartPolicy: OnFailure containers: - name: solver image: registry.berkelium.lbl.gov/sci-als/synchrotron-model:v1 command: ["python", "run_sweep.py", "--angles", "0-180", "--out", "/data/results"] volumeMounts: - name: storage-volume mountPath: /data resources: limits: cpu: "16" memory: "64Gi" nvidia.com/gpu: "1" volumes: - name: storage-volume persistentVolumeClaim: claimName: my-project-cephfs-pvcSubmit and check execution:
kubectl apply -f batch-simulation.yamlkubectl get jobs -n sci-myprojectParallel Indexed Jobs (Slurm Array Equivalent)
Section titled “Parallel Indexed Jobs (Slurm Array Equivalent)”To run 10 parallel sub-tasks where each worker receives its distinct index (JOB_COMPLETION_INDEX from 0 to 9):
apiVersion: batch/v1kind: Jobmetadata: name: parallel-array-simulation namespace: sci-myprojectspec: completions: 10 parallelism: 5 # Run 5 concurrent pods at a time completionMode: Indexed template: spec: restartPolicy: OnFailure containers: - name: worker image: python:3.11-slim command: ["python", "-c", "import os; print(f'Processing shard {os.environ.get(\"JOB_COMPLETION_INDEX\")}')"]