Shared infrastructure services for a datacenter are usually deployed on Virtual Machines, but there is a growing opportunity to run these services as containers in a highly-available Kubernetes cluster.
I have built a custom image which has a Chrony NTP daemon on a lightweight Alpine image and exposed it as a Service at port 123/udp. Running this service on your cluster just takes an apply:
kubectl apply -f https://raw.githubusercontent.com/fabianlee/docker-chrony-alpine/main/k8s-chrony-alpine.yaml
You may want to download this yaml instead and modify the ntp server pool (default=time.google.com), or other settings. The full github project is here, and dockerhub is here.
If you want to test this NTP server, then spin up my custom Debian-slim image that has the ntpdate client (~134Mb).
kubectl apply -f https://raw.githubusercontent.com/fabianlee/docker-debian-bullseye-slim-ntpclient/main/k8s-debian-slim.yaml
Go into the shell of this ‘debian-slim‘ pod and execute the ntp client call against the ClusterIP of the ‘chrony-alpine-service’ service.
# from debian-slim pod, query ntp service for time $ ntpdate -q <ClusterIP_of_chrony-alpine-service> server 10.152.183.20, stratum 2, offset -0.001112, delay 0.02611 2 Jun 20:22:09 ntpdate[133895]: adjust time server 10.152.183.20 offset -0.001112 sec
REFERENCES
fabianlee, Docker ntp image with alpine and chrony
fabianlee github, same concept with docker container and openntpd, but takes too long to sync