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

Viewed 5826

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.

2 Answers
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

It uses the system timezone, whatever that happens to be. Pretty much all server images default to UTC these days, but run date +"%Z %z" to check. Also remember that if you run kcm in a container, what actually matters is the localtime in that container, not the host OS. How you would change it depends on your OS, usually it's either something in systemd land or making a symlink from /etc/localtime to the right tzdata file.

I would not recommend doing this.

Related