All Products
Search
Document Center

Elastic Container Instance:Configure the NTP service

Last Updated:Mar 05, 2024

For some time-sensitive business scenarios, inaccurate time synchronization of containers may affect the normal operation of the business. For example, if the time of containers in a distributed system is inconsistent, the data may be inconsistent. If the log timestamp is inaccurate when you debug programs based on logs, the logs may be sorted in disorder and you may not correctly identify the error cause. When you deploy a containerized application in the time-sensitive business scenarios, you can configure the Network Time Protocol (NTP) service for the elastic container instance to ensure accurate time synchronization of containers in the instance. This solves the problems caused by inaccurate time and ensures data accuracy and normal business operation.

Description

Note

Only when you create an elastic container instance by calling an API operation, you can configure the NTP service for the instance.

When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the NtpServer.N parameter to configure the NTP service. The following table describes the parameter. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

NtpServer.N

array

ntp.aliyun.com

The address of the NTP server.

Example

  1. Create an elastic container instance and configure the NTP service for the instance.

    Sample parameters:

    ContainerGroupName=test-ntp
    NtpServer.1=100.100.XX.XX
    Container.1.Name=nginx
    Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/centos:7
    Container.1.Command=sleep
    Container.1.Arg=3600
  2. Connect the elastic container instance to query the time source of the containers of the instance.

    chronyc sources
    Note

    If 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. The following code shows a sample output.

    210 Number of sources = 7
    MS Name/IP address         Stratum Poll Reach LastRx Last sample               
    ===============================================================================
    ^* 100.100.XX.XX                 1   4   177    13    +22us[ +153us] +/-   10ms