Sign In

Curriculum 18: Jobs & CronJobs

Creating Jobs

12 min · 25 XP

Creating Jobs

A Job creates one or more pods and ensures a specified number of them successfully complete. Jobs are used for batch processing, data migrations, and one-time tasks.

Basic Job Definition

apiVersion: batch/v1
kind: Job
metadata:
  name: data-migration
spec:
  completions: 1
  parallelism: 1
  backoffLimit: 4
  activeDeadlineSeconds: 600
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: migrate
          image: myapp/migrate:v2
          command: ["python", "migrate.py"]
kubectl apply -f job.yaml
kubectl get jobs

Key Configuration Fields

completions controls how many pod completions are needed for the Job to succeed. The default is 1.

parallelism sets how many pods run concurrently. Setting this higher than 1 processes work items in parallel.

backoffLimit specifies the number of retries before marking the Job as failed. The default is 6. Each retry uses exponential backoff (10s, 20s, 40s, up to 6 minutes).

Running Parallel Jobs

spec:
  completions: 10
  parallelism: 3
  backoffLimit: 5

This configuration runs 3 pods at a time until 10 total completions are achieved.

Creating Jobs Imperatively

kubectl create job quick-task --image=busybox -- sh -c "echo 'Processing complete'"

# Generate YAML without creating
kubectl create job quick-task --image=busybox --dry-run=client -o yaml

Checking Job Status

kubectl get jobs data-migration
kubectl describe job data-migration
kubectl logs job/data-migration

The COMPLETIONS column shows progress (e.g., 3/10), indicating 3 of 10 required completions are done.