This guide will show you simple steps to Configure Chrony time synchronization with a remote server over the Network Time Protocol (NTP) on your OpenShift / OKD 4.x Cluster. OpenShift 4.x is based on CoreOS – RHCOS/FCOS and server modifications is via MachineConfig. So let’s configure Chrony time synchronization on our OpenShift / OKD cluster.

configure chrony openshift okd

The first step is to create a base64 encoded contents of the chrony.conf file.

cat >chrony.conf<<EOF
server 0.africa.pool.ntp.org iburst
server 1.africa.pool.ntp.org iburst
server 2.africa.pool.ntp.org iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony
keyfile /etc/chrony.keys
EOF

If you have your own NTP servers, edit the file and update server sections.

$ vi chrony.conf

Then encode it as base64

$ base64 -w0 chrony.conf

-- Saving to file ---
base64 -w0 chrony.conf> chrony.64

We can save the base64 value to variable:

chrony_base64=`base64 -w0 chrony.conf`

Create the MachineConfig files – for master / worker nodes.

for i in master worker; do
cat << EOF > ./${i}-chrony-configuration.yml
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  labels:
    machineconfiguration.openshift.io/role: ${i}
  name: ${i}-chrony-configuration
spec:
  config:
    ignition:
      config: {}
      security:
        tls: {}
      timeouts: {}
      version: 2.2.0
    networkd: {}
    passwd: {}
    storage:
      files:
      - contents:
          source: data:text/plain;charset=utf-8;base64,${chrony_base64}
          verification: {}
        filesystem: root
        mode: 420
        path: /etc/chrony.conf
  osImageURL: ""
EOF
done

Apply configuration files.

oc apply -f ./master-chrony-configuration.yml
oc apply -f ./worker-chrony-configuration.yml

The MachineConfig operator will apply Chrony configurations on all master and worker nodes then reboot them.

Wait for them to come up the confirm the settings.

$ oc adm debug node/<node-name>
  chroot /host

sh-4.4# cat /etc/chrony.conf 
server 0.africa.pool.ntp.org iburst
server 1.africa.pool.ntp.org iburst
server 2.africa.pool.ntp.org iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony
keyfile /etc/chrony.keys

The Chrony is now configured on OpenShift Cluster.

To set correct timezone you can ssh to the node and use timedatectl command:

$ sudo timedatectl set-timezone Africa/Nairobi
$ date
Sat Oct 31 19:57:23 EAT 2020

The output of the timedatectl command:

$ timedatectl 
               Local time: Sat 2020-10-31 20:02:12 EAT
           Universal time: Sat 2020-10-31 17:02:12 UTC
                 RTC time: Sat 2020-10-31 17:02:13
                Time zone: Africa/Nairobi (EAT, +0300)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

OpenShift Courses:

Practical OpenShift for Developers – New Course 2021

Ultimate Openshift (2021) Bootcamp by School of Devops

Check related guides available on our blog.

Run Ceph toolbox for Rook on Kubernetes / OpenShift

Add Harbor Image Registry Pull Secret to Kubernetes / OpenShift

How To Set Static IP Address on RHCOS / FCOS Machine

How To Allow Insecure Registries in OpenShift / OKD 4.x Cluster

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here