V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
eephee
V2EX  ›  Kubernetes

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

  •  
  •   eephee · 2023-02-13 13:23:44 +08:00 · 1527 次点击
    这是一个创建于 431 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    • 时区都是 Asia/Shanghai
    • 但是 pod 里面的时间比主机的时间快个就几十分钟

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

    10 条回复    2023-02-13 16:20:45 +08:00
    yasi
        1
    yasi  
       2023-02-13 13:29:59 +08:00
    tzdata
    mooyo
        2
    mooyo  
       2023-02-13 13:33:00 +08:00
    开 NTP 让他自动同步试试?
    aru
        3
    aru  
       2023-02-13 14:06:28 +08:00
    先检查下那两台主机的时间是否一致
    pod 时间和宿主机时间不一致没见过(时区不一样除外)
    eephee
        4
    eephee  
    OP
       2023-02-13 14:13:54 +08:00
    @yasi 感谢,只是我安装了 tzdata 然后 pdkg-reconfigure 选了 Asia/Shanghai 还是没生效
    eephee
        5
    eephee  
    OP
       2023-02-13 14:14:44 +08:00
    @mooyo 有效,我在主机上面装了一个 chrony(ntp for centos8),然后过了一会 k8s 的时间终于对上了,感谢。
    eephee
        6
    eephee  
    OP
       2023-02-13 14:16:59 +08:00
    @aru 感谢,但是确实时间显示( date 命令)是一样的,不过已经解决啦
    julyclyde
        7
    julyclyde  
       2023-02-13 15:29:42 +08:00
    容器内还有时钟设备吗??
    aapeli
        8
    aapeli  
       2023-02-13 15:31:19 +08:00
    挂载宿主的 /etc/localtime /etc/timezone 到容器里
    fengche361
        9
    fengche361  
       2023-02-13 15:43:52 +08:00
    挂载宿主的 /etc/timezone 能保证内外时区一致,挂载宿主的 /etc/localtime 能保证内外时间一致
    julyclyde
        10
    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 符号连接的来源
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:00 · PVG 14:00 · LAX 23:00 · JFK 02:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.