配置外部 NTP 服务器

本页面介绍了如何为 Google Distributed Cloud (GDC) 气隙设备配置外部 NTP 服务器。

只有在您想将设备与外部时间源同步时,才需要执行这些步骤。

准备工作

如需将设备与外部 NTP 服务器同步,请配置设备并安装软件

配置 NTP 中继

  1. 确定 GDC 空气隔离设备必须使用哪个 IP 地址才能访问您的 NTP 服务器。您可能需要调整防火墙规则以允许流量。

  2. 使用根 kubeconfig,修改管理平面集群中的 ntprelay CR 并添加 upstreamServers 部分。

    kubectl edit ntprelay bi-ntp-relay -n gpc-system
    ntprelay.system.private.gdc.goog/bi-ntp-relay edited
    kubectl get ntprelay bi-ntp-relay -n gpc-system -oyaml
    

    生成的 YAML 具有更新后的 .spec 部分,其中包含 IP,如以下示例所示:

    apiVersion: system.private.gdc.goog/v1alpha1
    kind: NTPRelay
    metadata:
      creationTimestamp: "2025-05-16T08:44:21Z"
      generation: 2
      name: bi-ntp-relay
      namespace: gpc-system
      resourceVersion: "10871409"
      uid: 6cde8e65-791c-4bc6-9a8b-d5c9bf103f8b
    spec:
      upstreamServers:
      - 192.0.2.030
    
  3. 验证每个节点上的时间:

    等待 3 分钟以留出同步时间,然后使用根 kubeconfig 在控制平面集群中运行以下命令:

    kubectl get pods -l app.kubernetes.io/name=ntp -n ntp-system -o name | xargs -P 0 -I {} kubectl exec {} -n ntp-system -- date; echo
    

    输出会显示每个节点的时间,与 NTP 服务器的时间一致。输出类似于以下内容:

    Defaulted container "ntp-image" out of: ntp-image, ntp-node-exporter
    Defaulted container "ntp-image" out of: ntp-image, ntp-node-exporter
    Defaulted container "ntp-image" out of: ntp-image, ntp-node-exporter
    Thu Nov  6 19:39:34 UTC 2025
    Thu Nov  6 19:39:34 UTC 2025
    Thu Nov  6 19:39:34 UTC 2025
    

调试连接问题

如果时间不一致,请在控制平面集群中使用根 kubeconfig 运行以下命令,以调试与 NTP 服务器的连接:

kubectl get pods -l app.kubernetes.io/name=ntp -n ntp-system -o name | xargs -I {} kubectl exec {} -n ntp-system -- sh -c "chronyc sources -v; echo; chronyc ntpdata"; echo

健康连接的输出如下所示。外部服务器的 IP 以 ^* 开头。在来源(例如 Remote address : 192.0.2.026)的数据中,TX 是发送的数据包数量,RX 是接收的数据包数量。如果 RX 为 0,则表示存在连接问题。检查防火墙,看看 NTP 请求是否通过:

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| /             'x' = may be in error, '~' = too variable, '?' = unusable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.0.2.026                   1   6    17    43   +286ns[  +36us] +/- 1160us
=? 192.0.2.029                 0   6     0     -     +0ns[   +0ns] +/-    0ns
=? 192.0.2.051                 0   6     0     -     +0ns[   +0ns] +/-    0ns
=? 192.0.2.059            0   6     0     -     +0ns[   +0ns] +/-    0ns

Remote address  : 192.0.2.026 (ACC03AF1)
Remote port     : 123
Local address   : 192.0.2.029 (0AA800D5)
Leap status     : Normal
Version         : 4
Mode            : Symmetric passive
Stratum         : 2
Poll interval   : 10 (1024 seconds)
Precision       : -25 (0.000000030 seconds)
Root delay      : 0.000381 seconds
Root dispersion : 0.000397 seconds
Reference ID    : ACC03BDF ()
Reference time  : Thu Nov 06 19:36:31 2025
Offset          : -0.000002443 seconds
Peer delay      : 0.000202604 seconds
Peer dispersion : 0.000000053 seconds
Response time   : 0.000097758 seconds
Jitter asymmetry: -0.37
NTP tests       : 111 111 1111
Interleaved     : No
Authenticated   : No
TX timestamping : Daemon
RX timestamping : Kernel
Total TX        : 67
Total RX        : 67
Total valid RX  : 67
Total good RX   : 67