kubernetes-101-jobs-cronjobs
Kubernetes 101 - Jobs & Cronjobs
December 15, 2022
Andrei Saizu

🔵  Job

A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate.

apiVersion: batch/v1

kind: Job

metadata:

    name: job

spec:

    template:

        containers:

         - name: nginx

           image: nginx:latest

           command: [”/bin/sh”, “-c”, “date;”]

    backoffLimit: 4

As pods successfully complete, the Job tracks the successful completions.  ✅

When a specified number of successful completions is reached, the task (Job) is complete. 🖐

🔵  CronJob

A CronJob creates Jobs on a repeating schedule. ⏱️

apiVersion: batch/v1

kind: CronJob

metadata:

    name: cronjob

spec:

    schedule: “*/1 * * * *”

    jobTemplate:

        spec:

            template:

                spec:

                    containers:

                     - name: nginx

                       image: nginx:latest

                       command: [”/bin/sh”, “-c”, “date;”]

CronJobs are meant for performing regular scheduled actions such as backups, report generation, and so on.

Each of those tasks should be configured to recur indefinitely (for example: once a day / week / month).

Follow the Kubernetes 101 series on mindit.io.

Check out new-spike.net for other articles on Kubernetes and much more! 🚀

Talk to the team

ASK US SOMETHING OR JUST SAY HELLO, WE'RE HERE.
Contact