>_ IzzyLab

Hands-on task

This task is step 13 of the course “Kubernetes: manifests from Namespace to RBAC”

CronJob on a schedule

medium~7 min

Prepare in /root/cronjob.yaml a CronJob cleanup: every 15 minutes it runs the image busybox:1.36 with the command sh -c "echo clean". You don't have to write it by hand — it's easier to generate it with a kubectl command using --dry-run=client -o yaml. Open the result in the Editor tab and find where the schedule and the command ended up in the manifest.

What you'll practise:
  • kubernetes
  • cronjob
  • kubectl
  • cron
  • dry-run

Topic breakdown

A CronJob runs a Job on a schedule in cron format (five fields: minutes, hours, day of month, month, day of week); */15 in the minutes field means "every 15 minutes". The kubectl create cronjob generator assembles the manifest from the image and schedule flags, and takes the container command after the -- separator. It's important to remember the order: all kubectl flags (including --dry-run=client -o yaml) must come BEFORE --, because everything after it is treated as the container command.

What's checked

  1. Manifest is valid
  2. Schedule every 15 minutes
  3. kind is CronJob
  4. Image busybox:1.36 and the command echo clean

What it looks like