> ## Content Index
> Fetch the complete content index at: https://scriptcrunch.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Create Jobs and CronJobs in Kubernetes?
- URL: https://scriptcrunch.com/create-jobs-and-cronjobs-on-kubernetes/
- Published: 2025-11-14T14:23:00.000Z
- Updated: 2026-06-23T08:55:51.000Z
- Author: Aswin Vijayan
- Tags: #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57, Kubernetes Certifications

In this blog, we will see how to create Jobs and CronJobs on [Kubernetes](https://scriptcrunch.com/install-kubernetes/).

Do you know what is Jobs and CronJobs on [Kubernetes](https://scriptcrunch.com/tag/kubernetes/)?

If you don't know don't worry I will give you a quick review of Jobs and CronJobs in Kubernetes.

## What Are Kubernetes Jobs?

Jobs are objects in [Kubernetes](https://scriptcrunch.com/kubernetes-authentication-and-authorization/) that deploy a pod, run tasks to completion, and then stop. They do not run continuously like other Kubernetes objects.

**Use cases:**

- One-time tasks
- Batch data processing
- [Database](https://scriptcrunch.com/tag/databases/) migrations
- Cleanup operations

First, here's a simple example of how to create Jobs on Kubernetes.

### Create Jobs

To create a Job, first, create a manifest file **job.yaml** and copy the below content into it

```yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: job
spec:
  template:
    spec:
      containers:
      - name: container
        image: busybox
        command: ["echo", "Hello, Kubernetes!"]
      restartPolicy: Never
```

Run the following command to create a Job:

```bash
kubectl apply -f job.yaml 
```

This will create a Job in the default namespace that runs the echo command on the busybox [container](https://scriptcrunch.com/kubernetes-init-containers/) and then gets terminated.

Check the Job:

```bash
kubectl get jobs
```

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/11/image-14.png)

Check the logs:

```bash
kubectl get pods
kubectl logs <pod-name>
```

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/11/image-15.png)

## What Are Kubernetes CronJobs?

CronJobs are also a Kubernetes object that schedules tasks to run at specified times. The job will automatically start according to the schedule specified in the job.

**Use cases:**

- Backups
- Log rotation
- Cleanup jobs
- Scheduled reports

### Create CronJobs

Now, let's see how to create CronJobs on Kubernetes.

To create a Job, first, create a manifest file **cronjob.yaml** and copy the below content into it

```yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: cronjob
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: container
            image: busybox
            command: ["echo", "Hello, Kubernetes!"]
          restartPolicy: Never
```

Run the following command to create a Job:

```bash
kubectl apply -f cronjob.yaml 
```

This will create a CronJob on the default namespace which schedules the command to run every 1 minute and print “Hello, Kubernetes!”

Check CronJob activity:

```bash
kubectl get cronjobs
```

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/11/image-16.png)

```bash
kubectl get jobs
```

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/11/image-17.png)

Check the logs:

```bash
kubectl get pods
kubectl logs <pod-name>
```

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/11/image-18.png)

### Important Fields for CKA

These fields often appear in exam scenarios.

**Jobs:**

- `completions`: how many times the Job must run successfully
- `parallelism`: how many Pods run at the same time
- `backoffLimit`: retry count before marking the Job as failed

**CronJobs:**

- `suspend: true` to pause CronJobs
- `concurrencyPolicy`:
  - `Allow` (default)
  - `Forbid` (do not run new Job if previous is still running)
  - `Replace` (kill old Job and run a new one)

## Conclusion

In this blog, you have learned about how to create Jobs and CronJobs and how they run tasks on Kubernetes.

I hope this blog gives a basic understanding of Kubernetes Jobs and CronJobs.