Our course you can check :- Udemy course
Kubernetes Job
✅ Purpose
A Job is used to run a one-time task in Kubernetes. It ensures that a specified number of pods successfully complete the task.
📌 Use Cases
- Data migration scripts
- Database backups
- Batch processing
- Cleanup tasks
- Sending reports or notifications
🧠 Key Features
- Runs once until completion
- Can retry on failure (based on
restartPolicy
) - Tracks completion status
⏰ Kubernetes CronJob
✅ Purpose
A CronJob is used to run recurring tasks on a schedule, similar to Linux cron jobs.
📌 Use Cases
- Scheduled backups
- Periodic data sync
- Log rotation
- Health checks
- Sending daily/weekly reports
🧠 Key Features
- Uses cron syntax (
*/5 * * * *
) to define schedule - Automatically creates Jobs at scheduled times
- Can control concurrency and history retention
Ques:-
DevOps team is crafting jobs in the Kubernetes cluster. While they're developing actual scripts/commands, they're currently setting up templates and testing jobs with dummy commands. Please create a job template as per details given below:
Create a job named countdown-datacenter.
The spec template should be named countdown-datacenter (under metadata), and the container should be named container-countdown-datacenter
Utilize image ubuntu with latest tag (ensure to specify as ubuntu:latest), and set the restart policy to Never.
Execute the command sleep 5
Ans:-
raj@jumphost ~$ vi job.yaml
raj@jumphost ~$ cat job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: countdown-datacenter
spec:
template:
metadata:
name: countdown-datacenter
spec:
containers:
- name: container-countdown-datacenter
image: ubuntu:latest
command: ["sleep", "5"]
restartPolicy: Never
raj@jumphost ~$ kubectl apply -f job.yaml
job.batch/countdown-datacenter created
raj@jumphost ~$ kubectl get job
NAME COMPLETIONS DURATION AGE
countdown-datacenter 1/1 12s 45s
raj@jumphost ~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
countdown-datacenter-msl9k 0/1 Completed 0 57s
raj@jumphost ~$
This will:
- Create a job named
countdown-datacenter
- Use the
ubuntu:latest
image - Run the dummy command
sleep 5
- Ensure the container is named
container-countdown-datacenter
- Set the restart policy to
Never
No comments:
Post a Comment