# Containers timezone not consistent with host

**URL:** <https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238>\
**Category:** General Discussions\
**Created:** [August 28, 2021, 6:09am UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238 "2021-08-28T06:09:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshen28](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/jshen28/32/8465_2.png) [@jshen28](https://discuss.kubernetes.io/u/jshen28)\
**Post date:** [August 28, 2021, 6:09am UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/1 "2021-08-28T06:09:20Z")

</div>

I find that although host timezone is set to asia/shanghai, container timezone is still incorrect. Is there way to synchronize these two? thank you.

### Cluster information:

Kubernetes version: 1.21  
Cloud being used: (put bare-metal if not on a public cloud) bare metal  
Installation method:  
Host OS: ubuntu 18.04  
CNI and version:  
CRI and version:

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [August 28, 2021, 11:09pm UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/2 "2021-08-28T23:09:34Z")

</div>

Should just need to fix `/etc/localtime` in your container images.

Something like this probably.

```nohighlight
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

```

Timezone stuff is just superficial though. Most of the base images I checked are on UTC-0 by default. If you work between multiple data centers, it makes more sense to just use UTC-0 everywhere and coordinate on that time.

There are some base images like `ubuntu:20.04` that don’t even ship with tzdata installed.

---

<div class="post-metadata">

**Author:** ![jshen28](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/jshen28/32/8465_2.png) [@jshen28](https://discuss.kubernetes.io/u/jshen28)\
**Post date:** [August 30, 2021, 1:59am UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/3 "2021-08-30T01:59:18Z")

</div>

Thank you very much for reply.

Modify Dockerfile and fix timezone works for me.

I am curious why k8s does not manage `/etc/localtime` just like `/etc/resolv.conf`?

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [August 30, 2021, 2:49am UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/4 "2021-08-30T02:49:57Z")

</div>

An opinionated handling of DNS resolution is a necessity, because you can’t connect to things inside (and maybe outside) of the cluster without this opinion. It’s arguable that everyone needs this and it should be standardized.

Timezones are superficial and it’s not necessary to set it to anything specific for applications to work. If you aggregate your log data somewhere, tools like Kibana will expect it to be in UTC anyway (I think this is because timestamps in Elasticsearch are UTC, don’t quote me on this, I’ve not messed with ELK stacks in a while).

Generally speaking, you can normalize timezone data later from wherever application you have processing it later.

---

<div class="post-metadata">

**Author:** ![jshen28](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/jshen28/32/8465_2.png) [@jshen28](https://discuss.kubernetes.io/u/jshen28)\
**Post date:** [August 30, 2021, 3:21pm UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/5 "2021-08-30T15:21:35Z")

</div>

it might be true for most applications but we also run virtual machines in container which kind of making it trickier because some virtual machine prefer to use loal time…

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [August 30, 2021, 3:29pm UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/6 "2021-08-30T15:29:11Z")

</div>

Are you using Kata containers and the virtual bios time is causing the time in the container to be wrong?

---

<div class="post-metadata">

**Author:** ![yonatankahana](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/yonatankahana/32/9842_2.png) [@yonatankahana](https://discuss.kubernetes.io/u/yonatankahana)\
**Post date:** [April 8, 2022, 11:27pm UTC](https://discuss.kubernetes.io/t/containers-timezone-not-consistent-with-host/17238/7 "2022-04-08T23:27:28Z")

</div>

you can use [k8tz](https://github.com/k8tz/k8tz) to automate timezone settings to all pods running in your cluster. you can also set different timezones for specific namespaces or pods using annotations.

here’s an example how to install k8tz with `Europe/London` as default timezone, and apply annotation to set `UTC` as the default timezone for namespace `special-namespace`.

```nohighlight
helm repo add k8tz https://k8tz.github.io/k8tz/
helm install k8tz k8tz/k8tz --set timezone=Europe/London
kubectl annotate namespace special-namespace k8tz.io/timezone=UTC

```
