I want to schedule kubernetes cronjob in my local timezone (GMT+7), currently when I schedule cronjob in k8s I need to schedule in UTC but I want to schedule in my local timezone, As specify in Kubernetes document, that I need to change timezone in kube-controller manager as follows
All CronJob schedule: times are based on the timezone of the kube-controller-manager.
If your control plane runs the kube-controller-manager in Pods or bare containers, the timezone set for the kube-controller-manager container determines the timezone that the cron job controller uses.
But I can't find a way to set timezone for kube-controller-manager, I'm using Kuberenetes on-premise v1.17, I found controller manager manifest file in - /etc/kubernetes/manifests/kube-controller-manager.yaml but can't find a way to or document to change the it's timezone.
Now, if you use Kubernetes version equal or more than 1.25 can use the field timeZone to specify a time zone for a CronJob.
spec:
timeZone: "Asia/Bangkok"
schedule: "0 17 * * *"
But if Kubernetes version < 1.25 and >= 1.21 you can fix the timezone in line with the schedule field.
spec:
schedule: "CRON_TZ=Asia/Bangkok 0 17 * * *"
Official document: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones
TimeZone list: https://www.ibm.com/docs/en/cloudpakw3700/2.3.0.0?topic=SS6PD2_2.3.0/doc/psapsys_restapi/time_zone_list.html
UPDATE 2023: WARNING OLD SYNTAX. See @Thanawat's answer, the official syntax has changed from what is shown in this answer.
spec:
schedule: "CRON_TZ=America/New_York */5 * * * *"
spec:
schedule: "CRON_TZ=Etc/UTC */5 * * * *"
By an "accident of implementation" timezone support was added to kubernetes cron scheduler.
available in v1.22 (next release)
Note: v1.22 should be released by end-of-year, Oct/Nov 2021
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With