To control which NTP server your ECI pod synchronizes with — for example, to meet compliance requirements, improve timestamp accuracy in distributed logs, or synchronize with an internal time source — add the k8s.aliyun.com/eci-ntp-server annotation when creating the pod.
Prerequisites
Before you begin, ensure that you have:
A Kubernetes cluster with the ECI add-on installed
kubectlconfigured to connect to your clusterThe IP address of your NTP server
Usage notes
Add annotations to the pod
metadatasection of your configuration file. For a Deployment, this isspec.template.metadata.annotations.Annotations take effect only when the pod is created. Adding or modifying the annotation on an existing pod has no effect.
Configure NTP for a pod
Create a Deployment manifest. Set the
k8s.aliyun.com/eci-ntp-serverannotation to your NTP server's IP address.apiVersion: apps/v1 kind: Deployment metadata: name: test-ntp labels: app: test spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: name: test-ntp labels: app: nginx alibabacloud.com/eci: "true" annotations: k8s.aliyun.com/eci-ntp-server: 100.100.XX.XX # Replace with your NTP server IP address. spec: containers: - name: nginx image: registry.cn-shanghai.aliyuncs.com/eci_open/centos:7 ports: - containerPort: 80 command: ["/bin/sh","-c","sleep 3600"]Apply the manifest.
kubectl create -f set-ntp.yaml
Verify NTP synchronization
Get the pod name.
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE test-ntp-599d5ff9f5-9kb56 1/1 Running 0 3m59sOpen a shell in the container.
kubectl exec -it test-ntp-599d5ff9f5-9kb56 -- bashCheck whether chrony is installed. If it is not, install it before proceeding.
yum -y install chronyCheck the NTP time source.
chronyc sourcesExpected output:
210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 100.100.XX.XX 2 6 377 35 +40us[ +135us] +/- 14msThe
^*in the first column marks the currently active time source. If your NTP server IP address appears on this line, time synchronization is working.