DEV Community

Fred Richards
Fred Richards

Posted on

Shift the TZ for your K8s CronJobs

In your Kubernetes clusters, the timezone is typically assumed to be UTC, which is a very cloud-native way to provision things. The resources you have might be across the globe, so having every node or host use the same timezone makes sense, especially if you're correlating information in logs.

But in other environments, there is a need to have the local timezone configured.

What happens if your cronjobs in the cluster are not aligned with the local timezone? This could cause some minor havoc.

The answer is simple. The timezone settings for cronjobs are managed by the kube-controller-manager component. Assuming all of your control-plane nodes are provisioned prior with localized and correct timezone settings, just add an extra mount, adding in /etc/localtime into the kube-controller-manager component.

Inside Rancher RKE it may look something like this in your cluster.yaml file:

services:
  kube-controller:
    extra_binds:
      - '/etc/localtime:/etc/localtime'
Enter fullscreen mode Exit fullscreen mode

Provision your clusters with the localtime setting mounted and your jobs will be in the proper timezone.

Latest comments (0)