We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

CronJobs

A CronJob creates a Job on a schedule. It's a lot like a "normal" cron job, but for Kubernetes.

The schedule uses the classic cron syntax, which is 5 fields separated by spaces:

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of the week (0 - 6, Sunday is 0)
│ │ │ │ │
* * * * *

A * means "every". For example:

  • * * * * *: Every minute

  • 0 * * * *: At the top of every hour

  • 0 2 * * *: Every day at 2 AM

  • 30 9 * * 1: Every Monday at 9:30 AM

A CronJob's jobTemplate is just a Job spec, so wrapping a Job in a schedule looks like this:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: synergychat-stats-report
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      backoffLimit: 4
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: synergychat-stats
              image: curlimages/curl:latest
              args:
                - -sf
                - http://crawler-service.crawler.svc.cluster.local/stats

Kubernetes keeps the last 3 successful Jobs and the last failed one, and deletes the rest, but if you want to, you can configure that with successfulJobsHistoryLimit and failedJobsHistoryLimit.

Assignment

Schedule the stats report.

Make sure kubectl proxy is running, then run and submit the CLI tests.