This topic describes how to configure the Network Time Protocol (NTP) service for Elastic Container Instance pods. The NTP service synchronizes the time between containers and the NTP server.
Configuration description
When you create an Elastic Container Instance-based pod, you can add the k8s.aliyun.com/eci-ntp-server
annotation to specify the address of the NTP server. This way, the time of the containers in the pod is synchronized with the time of the NTP server.
Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.
To use features of Elastic Container Instance, you can add annotations only when you create Elastic Container Instance-based pods. If you add or modify annotations when you update pods, these annotations do not take effect.
Configuration example
Create an application that is used to configure the NTP service.
kubectl create -f set-ntp.yaml
The following code provides the content of a sample set-ntp.yaml file:
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 # The IP address of your NTP server. spec: containers: - name: nginx image: registry.cn-shanghai.aliyuncs.com/eci_open/centos:7 ports: - containerPort: 80 command: ["/bin/sh","-c","sleep 3600" ]
Log on to the container and check whether the NTP service works as expected.
Query the information about the pod.
kubectl get pod
The following command output is returned:
NAME READY STATUS RESTARTS AGE test-ntp-599d5ff9f5-9kb56 1/1 Running 0 3m59s
Access the container.
kubectl exec -it test-ntp-599d5ff9f5-9kb56 -- bash
Query the source from which the time of the container is synchronized.
chronyc sources
NoteIf chrony is not installed, you can run the
yum -y install chrony
command to install chrony.If the IP address of the NTP server is returned, the NTP service works as expected. Sample command 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] +/- 14ms