CKAD — Managing Jobs & CronJobs

2 minute read

Managing Jobs and CronJobs

This page covers the essential kubectl commands for working with Jobs and CronJobs — listing, inspecting, deleting, and troubleshooting.

List and Inspect

# List all Jobs
kubectl get jobs

# List all CronJobs
kubectl get cronjobs

# Describe a Job (includes events and Pod status)
kubectl describe job backup-job

# Describe a CronJob
kubectl describe cronjob db-backup

# Check logs from a Job's Pod
kubectl logs job/backup-job

# Get Job YAML
kubectl get job backup-job -o yaml

Viewing Job Pods

# List Pods created by a specific Job
kubectl get pods -l job-name=backup-job

# List Pods created by all Jobs
kubectl get pods --selector=batch.kubernetes.io/job-name

# Watch Pods in real time
kubectl get pods -l job-name=backup-job -w

Delete Jobs and CronJobs

# Delete a Job (and its Pods)
kubectl delete job backup-job

# Delete a CronJob (and all its Jobs)
kubectl delete cronjob db-backup

# Delete all completed Jobs
kubectl delete jobs --field-selector status.successful=1

Important: Deleting a CronJob also deletes all Jobs it has created. Deleting a Job also deletes its Pods.

Suspend and Resume a CronJob

# Pause a CronJob (stops creating new Jobs)
kubectl patch cronjob db-backup -p '{"spec":{"suspend":true}}'

# Resume it
kubectl patch cronjob db-backup -p '{"spec":{"suspend":false}}'

# Verify
kubectl get cronjob db-backup
# SUSPEND column should show True or False

Manually Trigger a CronJob

# Create a one-time Job from a CronJob's template
kubectl create job db-backup-manual --from=cronjob/db-backup

# Check it ran
kubectl get jobs
kubectl logs job/db-backup-manual

This is useful for testing a CronJob without waiting for the next scheduled run.

Troubleshooting Jobs

Common Job Statuses

Status Meaning
Complete All completions succeeded
Failed backoffLimit reached or activeDeadlineSeconds exceeded
Active Pods are still running
Suspended Job is paused

Debugging Workflow

# 1. Check Job status
kubectl get job <name>

# 2. Get detailed events
kubectl describe job <name>

# 3. List the Job's Pods
kubectl get pods -l job-name=<name>

# 4. Check Pod logs
kubectl logs <pod-name>

# 5. Check Pod events (for scheduling or image pull issues)
kubectl describe pod <pod-name>

Common CronJob Issues

Problem Cause Fix
Jobs not being created CronJob is suspended Check suspend field
Missed schedules startingDeadlineSeconds too low Increase the deadline
Too many Jobs piling up History limits too high Set successfulJobsHistoryLimit
Overlapping Jobs causing issues concurrencyPolicy: Allow Switch to Forbid or Replace

Quick Reference

Task Command
List Jobs kubectl get jobs
List CronJobs kubectl get cronjobs
Describe Job kubectl describe job <name>
Job logs kubectl logs job/<name>
Job Pods kubectl get pods -l job-name=<name>
Delete Job kubectl delete job <name>
Delete CronJob kubectl delete cronjob <name>
Suspend CronJob kubectl patch cronjob <name> -p '{"spec":{"suspend":true}}'
Manual trigger kubectl create job <name> --from=cronjob/<cron-name>

Exam tip: The command kubectl create job <name> --from=cronjob/<cron-name> is extremely useful during the exam for testing CronJobs without waiting for the schedule.


Next: Put it all together with Jobs & CronJobs Lab →

Updated: