In Kubernetes, Jobs are used to run tasks that need to finish successfully (like batch jobs, log analysis, or report generation). Sometimes, we want to make sure a Job doesn’t run forever — and that’s where activeDeadlineSeconds comes in.
🔹 Step 1: What is activeDeadlineSeconds?
It sets the maximum time (in seconds) a Job can run.
If the Job does not finish within this time, Kubernetes terminates it automatically.
Useful for:
- Avoiding Jobs running indefinitely.
- Saving resources in case of failures or long-running processes.
Important:
- This field goes under Job spec (.spec.activeDeadlineSeconds).
- It applies to the entire Job, not just individual Pods.
🔹 Step 2: Example Job (job5.yaml)
apiVersion: batch/v1
kind: Job
metadata:
name: job5
spec:
template:
metadata:
name: job5
spec:
containers:
- name: job5
image: alpine
command: ['sh', '-c', 'echo Running Kubernetes Job Demo ; sleep 20']
restartPolicy: Never
backoffLimit: 4
completions: 4
parallelism: 2
activeDeadlineSeconds: 5 # ⛔ Will fail (less than sleep time)
👉 Here, each pod sleeps for 20 seconds, but the Job deadline is just 5 seconds. So, it fails.
🔹 Step 3: Deploy and Check the Job
# Deploy Job
kubectl apply -f job5.yaml
# List Jobs
kubectl get jobs
# Describe Job
kubectl describe job job5
# List Pods
kubectl get pods
✅ Observation:
Pods start but terminate early due to deadline.
Job shows 0/4 completions.
Sample Output:
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
job5 0/4 18s 18s
And describe shows:
Warning DeadlineExceeded job-controller Job was active longer than specified deadline
🔹 Step 4: Fix the Job with a Larger Deadline
Update job5.yaml:
activeDeadlineSeconds: 60 # ✅ Enough time to finish
Apply again:
kubectl apply -f job5.yaml
Now check:
kubectl get jobs
kubectl get pods
✅ Observation:
4 Pods complete successfully (2 at a time).
Job shows 4/4 completions.
Sample Output:
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
job5 4/4 34s 77s
🔹 Step 5: Clean Up
kubectl delete job job5
🎯 Final Thoughts
- activeDeadlineSeconds is a simple but powerful field for controlling job runtime.
- Helps prevent resource wastage and ensures timeouts are enforced.
- Always set it based on your workload needs.
🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.
— Latchu | Senior DevOps & Cloud Engineer
☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions
Top comments (0)