k8s 容器内部和主机时区一致但是时间不一致该从何查起?

2023-02-13 13:23:44 +08:00
 eephee

给客户测试用的私部环境,那边给了两台装有 CentOS8 的机器,一台做 master ,另一台做 worker ,我使用 kubeadm 搭建好之后,用 helm 把我们的服务装了上去。但是部署完成之后我发现 pod 里面的时间和主机的不一致,更奇怪的是,时区竟然是一致的:

我上网搜可能的解决方案,发现的都是针对 时区不一致、时差 8 小时 这种情况的解决方案。我这情况实在是不知道该从哪里入手去排查了,有 k8s 高手可以帮忙指点一下吗?

1548 次点击
所在节点    Kubernetes
10 条回复
yasi
2023-02-13 13:29:59 +08:00
tzdata
mooyo
2023-02-13 13:33:00 +08:00
开 NTP 让他自动同步试试?
aru
2023-02-13 14:06:28 +08:00
先检查下那两台主机的时间是否一致
pod 时间和宿主机时间不一致没见过(时区不一样除外)
eephee
2023-02-13 14:13:54 +08:00
@yasi 感谢,只是我安装了 tzdata 然后 pdkg-reconfigure 选了 Asia/Shanghai 还是没生效
eephee
2023-02-13 14:14:44 +08:00
@mooyo 有效,我在主机上面装了一个 chrony(ntp for centos8),然后过了一会 k8s 的时间终于对上了,感谢。
eephee
2023-02-13 14:16:59 +08:00
@aru 感谢,但是确实时间显示( date 命令)是一样的,不过已经解决啦
julyclyde
2023-02-13 15:29:42 +08:00
容器内还有时钟设备吗??
aapeli
2023-02-13 15:31:19 +08:00
挂载宿主的 /etc/localtime /etc/timezone 到容器里
fengche361
2023-02-13 15:43:52 +08:00
挂载宿主的 /etc/timezone 能保证内外时区一致,挂载宿主的 /etc/localtime 能保证内外时间一致
julyclyde
2023-02-13 16:20:45 +08:00
你大概是把俩文件搞反了

https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_431.html
If the TZ environment variable does not have a value, the operation chooses a time zone by default. In the GNU C library, the default time zone is like the specification `TZ=:/etc/localtime'

If characters begins with a slash, it is an absolute file name; otherwise the library looks for the file `/share/lib/zoneinfo/characters'. The `zoneinfo' directory contains data files describing local time zones in many different parts of the world. The names represent major cities, with subdirectories for geographical areas; for example, `America/New_York', `Europe/London', `Asia/Hong_Kong'. These data files are installed by the system administrator, who also sets `/etc/localtime' to point to the data file for the local time zone.

这是 localtime 符号连接的来源

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/915650

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX