The earlier blog: Some Usage of Cron Jobs in Kubernetes introduced basic cron job usage. But during use I found a task scheduled for 8 a.m. executes in the afternoon — exactly 8 hours apart, so I suspected a timezone problem.
Documentation
Facing this problem I went straight to the docs: CronJob.
This document’s updates went back and forth for a long time; the doc kept agonizing over what the scheduled task’s execution references. The content below is a version updated after March 2020 — I won’t paste the earlier incorrect versions, only a correct one:
1 | Caution: |
The Chinese translation of the doc had never been updated, so I helped update it too:
1 | 警告: |
Solution
Since we learned the scheduled task’s scheduling relates to the control-manager container’s timezone, just consider modifying that container’s timezone.
For maintainability, build a new image based on the original one.
1 | FROM <dockerhub>/fengyuhao/kube-controller-manager:v1.17.0 |
1 | docker build . -t <dockerhub>/fengyuhao/kube-controller-manager:hk-v1.17.0 |
Then for the kubernetes master machine, change the control-manager configuration; kubernetes will apply the new configuration automatically:
1 | # file location: /etc/kubernetes/manifests/kube-controller-manager.yaml |
Please replace the corresponding dockerhub and image addresses yourselves.
You can use kubectl -n kube-system get pods to confirm the controller update.