Skip to content

RKE2 how to set the timezone

Article Number: 000021862

Environment

RKE2

Situation

Containers do not inherit timezones from host machines and have only accessed to the clock from the kernel - which is always UTC. The default timezone for most images is UTC, yet it is not guaranteed and may be different from container to container since it can be changed on a pod or image level.

Cause

Rancher started including the tzdb package in k8s releases from January 2025 onwards.

Prior to this it as not possible to set the Timezone.

See this issue:
https://github.com/rancher/rke2/issues/7331

Resolution

You can use the following environment variables to set the desired timezone in the various pods by editing the cluster YAML:

    machineSelectorConfig:
      - config:
            kube-apiserver-extra-env: "TZ=<timezone>"
            kube-scheduler-extra-env: "TZ=<timezone>"
            kube-controller-manager-extra-env: "TZ=<timezone>"
            kube-proxy-extra-env: "TZ=<timezone>"
            etcd-extra-env: "TZ=<timezone>"
            cloud-controller-manager-extra-env: "TZ=<timezone>"

This assumes the tzdb package is present on the nodes. Rancher started including this in their k8s releases from January 2025 onwards.

For other non-static pods and workloads you may have, you can consider using k8tz that creates a admission controller that injects the timezones into any pods created. 
See here: https://github.com/k8tz/k8tz