V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
eephee

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

  •  
  •   eephee · Feb 13, 2023 · 2535 views
    This topic created in 1172 days ago, the information mentioned may be changed or developed.

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

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

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

    10 replies    2023-02-13 16:20:45 +08:00
    C1V7dYXW4PN67euV
        1
    C1V7dYXW4PN67euV  
       Feb 13, 2023
    tzdata
    mooyo
        2
    mooyo  
       Feb 13, 2023
    开 NTP 让他自动同步试试?
    aru
        3
    aru  
       Feb 13, 2023
    先检查下那两台主机的时间是否一致
    pod 时间和宿主机时间不一致没见过(时区不一样除外)
    eephee
        4
    eephee  
    OP
       Feb 13, 2023
    @yasi 感谢,只是我安装了 tzdata 然后 pdkg-reconfigure 选了 Asia/Shanghai 还是没生效
    eephee
        5
    eephee  
    OP
       Feb 13, 2023
    @mooyo 有效,我在主机上面装了一个 chrony(ntp for centos8),然后过了一会 k8s 的时间终于对上了,感谢。
    eephee
        6
    eephee  
    OP
       Feb 13, 2023
    @aru 感谢,但是确实时间显示( date 命令)是一样的,不过已经解决啦
    julyclyde
        7
    julyclyde  
       Feb 13, 2023
    容器内还有时钟设备吗??
    aapeli
        8
    aapeli  
       Feb 13, 2023
    挂载宿主的 /etc/localtime /etc/timezone 到容器里
    fengche361
        9
    fengche361  
       Feb 13, 2023
    挂载宿主的 /etc/timezone 能保证内外时区一致,挂载宿主的 /etc/localtime 能保证内外时间一致
    julyclyde
        10
    julyclyde  
       Feb 13, 2023
    你大概是把俩文件搞反了

    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 符号连接的来源
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2189 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 00:34 · PVG 08:34 · LAX 17:34 · JFK 20:34
    ♥ Do have faith in what you're doing.