[bitnami/mongodb] Time Zone
Which chart: Mongodb Helm Chart ( mongodb-10.26.3)
Describe the bug
Time zone in mongodb container seems to be not the same as host time zone Time zone: Europe/Paris (CEST, +0200)
Exemple.
mongodb container's log:
mongodb 07:47:24.58 INFO ==> Deploying MongoDB from scratch...
mongodb container always use UTC0 as TZ instead of local time TZ (Europe/Paris)
$ timedatectl
Local time: Thu 2021-10-14 09:48:29 CEST
Universal time: Thu 2021-10-14 07:47:24 UTC
RTC time: Thu 2021-10-14 07:47:24
Time zone: Europe/Paris (CEST, +0200)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2021-03-28 01:59:59 CET
Sun 2021-03-28 03:00:00 CEST
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2021-10-31 02:59:59 CEST
Sun 2021-10-31 02:00:00 CET
You need to check the date in the container, not in the host machine:
$ kubectl logs mongo-mongodb-69ff5c6469-nxpct -n mongo
...
{"t":{"$date":"2021-10-14T10:22:17.968+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn895","msg":"Connection ended","attr":{"remote":"127.0.0.1:48790","connectionId":895,"connectionCount":0}}
{"t":{"$date":"2021-10-14T10:22:18.266+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:48794","connectionId":896,"connectionCount":1}}
{"t":{"$date":"2021-10-14T10:22:18.267+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn896","msg":"client metadata","attr":{"remote":"127.0.0.1:48794","client":"conn896","doc":{"application":{"name":"MongoDB Shell"},"driver":{"name":"MongoDB Internal Client","version":"4.4.9"},"os":{"type":"Linux","name":"PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"","architecture":"x86_64","version":"Kernel 5.4.129+"}}}}
{"t":{"$date":"2021-10-14T10:22:18.275+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn896","msg":"Connection ended","attr":{"remote":"127.0.0.1:48794","connectionId":896,"connectionCount":0}}
$ kubectl exec -t mongo-mongodb-69ff5c6469-nxpct -n mongo -- date
Thu Oct 14 10:22:28 UTC 2021
Hello @carrodher
This the date in the container
Thu 14 Oct 2021 12:40:58 PM UTC
So , as you can see above the container is using UTC instead of local TZ (UTC +2) .
I don't know if it's possible to make container change its TZ at the starting time.
You can use the extraEnvVars parameter in the Helm chart to set the timezone (see https://github.com/bitnami/charts/tree/master/bitnami/mongodb#add-extra-environment-variables), something like:
extraEnvVars:
- name: TZ
value: 'Asia/Shanghai'
then install the chart using the above values file with the -f flag.
$ helm install mongo bitnami/mongodb -n mongo --create-namespace -f values.yaml
$ kubectl get pods -n mongo
NAME READY STATUS RESTARTS AGE
mongo-mongodb-6456d497b-nvq6z 1/1 Running 0 48s
$ kubectl exec -t mongo-mongodb-6456d497b-nvq6z -n mongo -- date
Thu Oct 14 23:41:37 CST 2021
$ helm install mongo2 bitnami/mongodb -n mongo2 --create-namespace
$ kubectl get pods -n mongo2
NAME READY STATUS RESTARTS AGE
mongo2-mongodb-5b58f6cf-96xnh 1/1 Running 0 37s
$ kubectl exec -t mongo2-mongodb-5b58f6cf-96xnh -n mongo2 -- date
Thu Oct 14 15:43:26 UTC 2021
I just tried as well using docker-compose to show how the timezone changes "on the fly" when using the environment variable:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60e9c3ae8ea3 bitnami/mongodb:4.4 "/opt/bitnami/script…" About a minute ago Up About a minute 0.0.0.0:27017->27017/tcp bitnami-docker-mongodb_mongodb_1
$ docker-compose exec 60e9c3ae8ea3 -- /bin/bash
I have no name!@60e9c3ae8ea3:/$ date
Thu Oct 14 15:33:21 UTC 2021
I have no name!@60e9c3ae8ea3:/$ TZ=Asia/Shangha date
Thu Oct 14 23:35:21 CST 2021