dockerkuberneteskubernetes-cronjob

Kubernetes Cronjob schedule in local timezone (custom timezone) as it always UTC


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.


Solution

  • 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