0
0
Kubernetesdevops~30 mins

Jobs and CronJobs for batch processing in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Jobs and CronJobs for batch processing
📖 Scenario: You work in a company that needs to run tasks automatically in Kubernetes. Some tasks run once, and some run repeatedly on a schedule. You will create Kubernetes Job and CronJob resources to handle these batch tasks.
🎯 Goal: Learn how to create a Kubernetes Job to run a one-time batch task and a CronJob to run a task on a schedule.
📋 What You'll Learn
Create a Kubernetes Job YAML manifest with exact metadata and spec
Add a CronJob YAML manifest with a schedule and job template
Use the correct container image and command for the batch task
Print the created resource names to confirm creation
💡 Why This Matters
🌍 Real World
Companies use Kubernetes Jobs to run one-time batch tasks like data processing or backups. CronJobs run scheduled tasks like report generation or cleanup jobs automatically.
💼 Career
Knowing how to create and manage Jobs and CronJobs is essential for DevOps engineers and site reliability engineers to automate and maintain batch workloads in Kubernetes.
Progress0 / 4 steps
1
Create a Kubernetes Job manifest
Create a YAML manifest named job.yaml for a Kubernetes Job with these exact details: metadata name batch-job, spec template with a single container named batch-task using image busybox and command ["/bin/sh", "-c", "echo Hello from Job"]. The restart policy must be Never.
Kubernetes
Need a hint?

Remember to set kind to Job and use the exact container name and command.

2
Create a Kubernetes CronJob manifest
Create a YAML manifest named cronjob.yaml for a Kubernetes CronJob with these exact details: metadata name batch-cronjob, schedule "*/5 * * * *" (every 5 minutes), job template with a single container named cron-task using image busybox and command ["/bin/sh", "-c", "echo Hello from CronJob"]. The restart policy must be OnFailure.
Kubernetes
Need a hint?

Use kind: CronJob and set the schedule to run every 5 minutes exactly as shown.

3
Apply the Job and CronJob manifests
Write the exact kubectl commands to apply both job.yaml and cronjob.yaml files to the Kubernetes cluster.
Kubernetes
Need a hint?

Use kubectl apply -f with the exact file names.

4
Print the names of created Job and CronJob
Write the exact kubectl commands to list the names of Jobs and CronJobs in the current namespace.
Kubernetes
Need a hint?

Use kubectl get jobs and kubectl get cronjobs with custom columns to show only names.