In Kubernetes, we have ReplicaSets, DaemonSets, StatefulSets, and Deployments, all of which ensure that their Pods are always running. If a Pod fails, the controller restarts or reschedules it to another node to maintain the application's availability.
However, sometimes, we need to run one-time or finite tasks that do not require continuous execution. This is where Jobs come into play.
📌 Jobs are used for:
✅ Database Backups – Automating DB snapshots
✅ Helm Charts – Some Helm-based applications use Jobs
✅ Batch Processing – Running computations or data processing tasks
✅ Scheduled Tasks – Executing a task at fixed intervals (like CronJobs)
✅ Log Rotation – Cleaning up old logs automatically
Here is an example of how to define a Job in Kubernetes using a YAML file:
apiVersion: batch/v1
kind: Job
metadata:
name: testjob
spec:
template:
metadata:
name: testjob
spec:
containers:
- name: counter
image: centos:7
command: ["bin/bash", "-c", "echo Technical-Guftgu; sleep 5"]
restartPolicy: Never
apiVersion: batch/v1
→ Specifies that this resource is a Job.kind: Job
→ Defines the resource type as a Job.metadata.name: testjob
→ Assigns a name to the Job.