Jobs

TOC

Understanding Jobs

Refer to the official Kubernetes documentation: Jobs

A Job provide different ways to define tasks that run to completion and then stop. You can use a Job to define a task that runs to completion, just once.

  • Atomic Execution Unit: Each Job manages one or more Pods until successful completion.
  • Retry Mechanism: Controlled by spec.backoffLimit (default: 6).
  • Completion Tracking: Use spec.completions to define required success count.

YAML file example

# example-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: data-processing-job
spec:
  completions: 1 # Number of successful completions required
  parallelism: 1 # Maximum parallel Pods
  backoffLimit: 3 # Maximum retry attempts
  template:
    spec:
      restartPolicy: Never # Job-specific policy (Never/OnFailure)
      containers:
        - name: processor
          image: alpine:3.14
          command: ['/bin/sh', '-c']
          args:
            - echo "Processing data..."; sleep 30; echo "Job completed"

Execution Overview

Each Job execution in Kubernetes creates a dedicated Job object, enabling users to:

  • Creating a job via

    kubectl apply -f example-job.yaml
  • Track job lifecycle via

    kubectl get jobs
  • Inspect execution details via

    kubectl describe job/<job-name>
  • View Pod logs via

    kubectl logs <pod-name>