2 min read

[k8s] Setup timezone on cronjob

Standard time and daylight time have been a nightmare for cron configuration in Kubernetes. Fortunately it is an old nightmare thanks to the cronjob .spec.timeZone configuration
[k8s] Setup timezone on cronjob
ℹ️
Any resemblance to real events and/or to real persons, living or dead, is purely coincidental

⏳ Once upon a time, there was a poor guy who had to configure a fake meeting reminder to edit the UTC Kubernetes cronjob configuration two times in a year:

  • on standard time start
  • on the switch to the daylight time

All that stuff was to guarantee that a routine/sw was running at a specific local time (ex. Europe/Rome)

via GIPHY

But since 1.27 kubernetes version, this is finally an old nightmare since .spec.timeZone (talking about CronJob resource) has promoted to GA.

via GIPHY

FEATURE STATE: Kubernetes v1.27 [stable]
For CronJobs with no time zone specified, the kube-controller-manager interprets schedules relative to its local time zone.
You can specify a time zone for a CronJob by setting .spec.timeZone to the name of a valid time zone. For example, setting .spec.timeZone: "Etc/UTC" instructs Kubernetes to interpret the schedule relative to Coordinated Universal Time.
A time zone database from the Go standard library is included in the binaries and used as a fallback in case an external database is not available on the system.

CronJob limitations
Unsupported TimeZone specification
Specifying a timezone using CRON_TZ or TZ variables inside .spec.schedule is not officially supported (and never has been).
Starting with Kubernetes 1.29 if you try to set a schedule that includes TZ or CRON_TZ timezone specification, Kubernetes will fail to create the resource with a validation error. Updates to CronJobs already using TZ or CRON_TZ will continue to report a warning to the client.

CronJob
A CronJob starts one-time Jobs on a repeating schedule.
Tweets by YBacciarini