設定外部 NTP 伺服器

本頁說明如何為 Google Distributed Cloud (GDC) 氣隙裝置設定外部 NTP 伺服器。

只有在想將設備與外部時間來源同步時,才需要執行這些步驟。

事前準備

如要將設備與外部 NTP 伺服器同步,請設定裝置並安裝軟體

設定 NTP 轉發

  1. 找出 GDC 氣隙裝置必須用來存取 NTP 伺服器的 IP 位址。您可能必須調整防火牆規則,允許流量通過。

  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. 確認每個節點上的時間:

    等待三分鐘讓系統有時間同步處理,然後使用根 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