🛠 Jobs in Kubernetes (Detailed Explanation)

🔹 What are Jobs in Kubernetes? ⇒

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.

🔹 Use Cases of Jobs in Kubernetes ⇒

📌 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

📄 Example: Job Manifest in Kubernetes ⇒

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

🔹 Explanation: