World map

 

BM: Baca dalam Bahasa Melayu

World K2: Trays & Orders

Jobs and CronJobs

You will learn: to run a task once with a Job, and on a schedule with a CronJob.

Checked with Kubernetes 1.37 on 31 Oct 2026

The problem

After closing, someone counts the plates once, then goes home. You make that counter a Deployment. What happens?

Pick one answer.

Watch

You are here: cluster kind-dev namespace default
The Job tally runs once. Its status is Complete with 1/1 completions. Its log says counting plates, 42 plates. Terminal output: $ kubectl apply -f tally.yaml job.batch/tally created $ kubectl wait --for=condition=complete job/tally --timeout=60s job.batch/tally condition met $ kubectl get job tally NAME STATUS COMPLETIONS DURATION AGE tally Complete 1/1 2s 2s $ kubectl logs job/tally counting plates 42 plates

A Job: A task that runs until it finishes, like counting the plates once. runs a task until it finishes, then stops. STATUS says Complete. COMPLETIONS says 1/1.

Predict

The Job’s pod finished well. What does kubectl get pods show for it?

Pick one answer.

Try it

A Job may not use restartPolicy: Always. Read the real error. Pick one of the values it lists.

Fix the manifest, then press Apply.

tally.yaml13 lines

Watch

A CronJob: Makes a Job on a schedule, like counting the plates every night. makes a Job on a schedule. Its five fields are minute, hour, day, month and weekday.

spec:
  schedule: "30 23 * * *"

When does this run?

Pick one answer.

Try it

Do not wait for tonight. Apply nightly.yaml. Then start one count now: kubectl create job tally-now --from=cronjob/nightly.

You are here: cluster kind-dev namespace default
Stalls: 3. Trays: 0 (0 ready). Waiting for a stall: 0.
dev-control-planeOpenManager

No trays here.

dev-workerOpen

No trays here.

dev-worker2Open

No trays here.

Time: +0s (sped up)

Check

Deployment, Job or CronJob? Sort each task.

Drag a card into a box. Or tap the card, then tap the box.

        You did it!

        You can now run a task once, or on a schedule.

        Go deeper (optional)

        A failing Job retries, up to backoffLimit times (6 by default). Without timeZone, a CronJob follows the cluster’s clock, often UTC. A CronJob keeps the last 3 good Jobs and removes older ones.

        Real rep (optional): on a throwaway cluster, run kubectl get cronjobs and kubectl get jobs.