6.5.8.6. NTP 没有同步

OpenShift Container Platform 集群的部署需要集群节点间的 NTP 时钟已同步。如果没有同步时钟,当时间差大于 2 秒时,部署可能会因为时钟偏移而失败。

流程

  1. 检查集群节点的 AGE 的不同。例如:

    $ oc get nodes
    NAME                         STATUS   ROLES    AGE   VERSION
    master-0.cloud.example.com   Ready    master   145m   v1.16.2
    master-1.cloud.example.com   Ready    master   135m   v1.16.2
    master-2.cloud.example.com   Ready    master   145m   v1.16.2
    worker-2.cloud.example.com   Ready    worker   100m   v1.16.2
  2. 检查因为时钟偏移导致的时间延迟。例如:

    $ oc get bmh -n openshift-machine-api
    master-1   error registering master-1  ipmi://<out-of-band-ip>
    $ sudo timedatectl
                   Local time: Tue 2020-03-10 18:20:02 UTC
               Universal time: Tue 2020-03-10 18:20:02 UTC
                     RTC time: Tue 2020-03-10 18:36:53
                    Time zone: UTC (UTC, +0000)
    System clock synchronized: no
                  NTP service: active
              RTC in local TZ: no

处理现有集群中的时钟偏移

  1. 创建 chrony.conf 文件并将其编码为 base64 字符串。例如:

    $ cat << EOF | base 64
    server <NTP-server> iburst1
    stratumweight 0
    driftfile /var/lib/chrony/drift
    rtcsync
    makestep 10 3
    bindcmdaddress 127.0.0.1
    bindcmdaddress ::1
    keyfile /etc/chrony.keys
    commandkey 1
    generatecommandkey
    noclientlog
    logchange 0.5
    logdir /var/log/chrony
    EOF
    1
    <NTP-server> 替换为 NTP 服务器的 IP 地址。复制输出。
    [text-in-base-64]
  2. 创建 MachineConfig 对象,将 base64 字符串替换为上一步输出中生成的 [text-in-base-64] 字符串。以下示例将文件添加到 Control Plane(master)节点。您可以修改 worker 节点的文件,或为 worker 角色创建额外的机器配置。

    $ cat << EOF > ./99_masters-chrony-configuration.yaml
    apiVersion: machineconfiguration.openshift.io/v1
    kind: MachineConfig
    metadata:
      creationTimestamp: null
      labels:
        machineconfiguration.openshift.io/role: master
      name: 99-master-etc-chrony-conf
    spec:
      config:
        ignition:
          config: {}
          security:
            tls: {}
          timeouts: {}
          version: 3.1.0
        networkd: {}
        passwd: {}
        storage:
          files:
          - contents:
              source: data:text/plain;charset=utf-8;base64,[text-in-base-64]1
            group:
              name: root
            mode: 420
            overwrite: true
            path: /etc/chrony.conf
            user:
              name: root
      osImageURL: ""
    1
    [text-in-base-64] 替换为 base64 字符串。
  3. 对配置文件做一个副本备份。例如:

    $ cp 99_masters-chrony-configuration.yaml 99_masters-chrony-configuration.yaml.backup
  4. 应用配置文件:

    $ oc apply -f ./masters-chrony-configuration.yaml
  5. 确定 System clock synchronized 的值为 yes

    $ sudo timedatectl
                   Local time: Tue 2020-03-10 19:10:02 UTC
               Universal time: Tue 2020-03-10 19:10:02 UTC
                     RTC time: Tue 2020-03-10 19:36:53
                    Time zone: UTC (UTC, +0000)
    System clock synchronized: yes
                  NTP service: active
              RTC in local TZ: no

    要在部署前设置时钟同步,请生成清单文件并将该文件添加到 openshift 目录中。例如:

    $ cp chrony-masters.yaml ~/clusterconfigs/openshift/99_masters-chrony-configuration.yaml

    然后继续创建集群。