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.
As mentioned by @armando You will not be able to globally set the TZ in a cluster.
You can use a pod preset
and predefine a timezone.
Use that pod preset in your pod.
This method is somewhat similar to (https://evalle.xyz/posts/kubernetes-tz/) but this will be a little easier at the time of pods creation. Checkout podpreset.
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, in (https://evalle.xyz/posts/kubernetes-tz/) 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 (https://evalle.xyz/posts/kubernetes-tz/).
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.
You can set the timezone of the cluster using deploy.yaml file. Add the following lines according to your requirement:
volumes:
- name: tz-config
hostPath:
path: /usr/share/zoneinfo/Europe/Prague
What article describe is how to pass localtime
to POD, not a cluster. POD's are ephemeral, and yes you can use kubectl patch, or adding some kind curl call to API to provide the same patch to apply these changes. But you better to change all configs for pods if you want to pass and keep this info in all your deployments.