I am currently deploying openfaas on my local virtual machine's kubernetes cluster. I found that the time zone of the container started after publishing the function is inconsistent with the host machine. How should I solve this problem?
[root@k8s-node-1 ~]# date
# Host time
2021年 06月 09日 星期三 11:24:40 CST
[root@k8s-node-1 ~]# docker exec -it 5410c0b41f7a date
# Container time
Wed Jun 9 03:24:40 UTC 2021
As @coderanger pointed out in the comments section, the timezone difference is not related to
OpenFaaS
.It depends on the image you are using, most of the images use
UTC
timezone. Normally this shouldn't be a problem, but in some special cases you may want to change this timezone.As described in this article, you can use the
TZ
environment variable to set the timezone of a container (there are also other ways to change the timezone).If you have your own
Dockerfile
, you can use the ENV instruction to set this variable:NOTE: The
tzdata
package has to be installed in the container for setting theTZ
variable.