CronJob Schedule Syntax and Timezone
You'll learn how to write cron schedules and handle timezone settings for automated Kubernetes jobs.
Understanding Cron Schedule Syntax
A CronJob schedule follows the traditional Unix cron format with five time fields:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6, Sunday = 0)
│ │ │ │ │
* * * * *
Think of it like setting a recurring alarm clock—each field narrows down when the job should run.
Common Schedule Patterns
- Every hour:
0 * * * *(at minute 0) - Daily at 3 AM:
0 3 * * * - Every weekday at 9 AM:
0 9 * * 1-5 - Every Sunday at midnight:
0 0 * * 0 - Every 15 minutes:
*/15 * * * *
Special characters:
*= every unit (any value)*/n= every n unitsn-m= range from n to mn,m= specific values n and m
Timezone Configuration
By default, CronJobs use the timezone of the kube-controller-manager (often UTC). You can specify a different timezone using the timeZone field in your CronJob spec:
spec:
schedule: "0 9 * * *"
timeZone: "America/New_York" # Runs at 9 AM Eastern
Without this, your "9 AM daily job" might run at 2 AM local time if the cluster is in UTC!
Key Takeaway: Cron schedules use five time fields (minute, hour, day, month, weekday) with special characters for patterns, and you should always set an explicit timeZone to avoid unexpected execution times across regions.