Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change TimeZone of entire Kubernetes cluster?

I want to change timezone of our entire on-prim kubernetes Cluster from default UTC to America/Los_Angeles.

I am aware about changing it for single deployment by using volumes[ref.: https://evalle.xyz/posts/kubernetes-tz/] This is tedious job to do, as there are many pods in my cluster.

I am looking out better option to do it for entire cluster one go. Any help much appreciated.

like image 963
ron shine Avatar asked Oct 25 '25 11:10

ron shine


2 Answers

TL;DR: You will not be able to globally set the TZ in a cluster.

Based on the answer of “KarlKFI” in (What time is it in a Kubernetes pod?)

The clock in a container is the same as the host machine because it’s controlled by the kernel.

As you already mentioned, you can change the TZ of the POD by binding the zoneinfo of the host OS.

So the TIME ZONE (TZ) is something that is locally controlled at POD level and can’t be changed globally because this should be done within the POD definition.

If you want to change the TZ without binding the zoneinfo of the host OS, based on (https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes) you may change it by setting the TZ environment variable. If you change your image and set the TZ environment variable in there, when the POD is created it will inherit from the image so the POD will be created with the TZ environment variable set.

So your only options are:

1.- Bind the zoneinfo of the host OS in each POD.

2.- Change your TimeZone on each node of your cluster.

3.- Set the TZ environment variable on your IMAGE so the POD will inherit the value when is created.

like image 67
Armando Cuevas Avatar answered Oct 27 '25 03:10

Armando Cuevas


It can be easily done by using k8tz, a kubernetes admission controller and a CLI tool to inject timezones into Pods that can be installed on the cluster using Helm.

helm repo add k8tz https://k8tz.github.io/k8tz/
helm install k8tz k8tz/k8tz --set timezone=America/Los_Angeles

After it's installed, any pod created on the cluster will be mutated by k8tz admission controller to make sure the timezone is explicitly set to America/Los_Angeles. You can choose a different timezone for different namespaces or pods using the k8tz.io/timezone annotation.

DISCLAIMER: I am the author of k8tz.

like image 35
Yonatan Kahana Avatar answered Oct 27 '25 04:10

Yonatan Kahana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!