All Products
Search
Document Center

Configure NTP for pods

Last Updated: Oct 27, 2021

This topic describes how to configure the Network Time Protocol (NTP) service for pods that run on a Virtual Kubelet node. The NTP service synchronizes the time between containers and the NTP server.

Prerequisites

Virtual Kubelet is upgraded to the latest version. For more information, see Update Virtual Kubelet.

Background information

Different types of Kubernetes clusters require different operations to update Virtual Kubelet.

  • For Serverless Kubernetes (ASK) clusters, the system automatically updates Virtual Kubelet.

  • For Container Service for Kubernetes (ACK) clusters, the update method of Virtual Kubelet varies based on the edition of the clusters. For managed ACK clusters, the system automatically updates Virtual Kubelet. For dedicated ACK clusters, you must manually update Virtual Kubelet.

  • For self-managed Kubernetes clusters, you must manually update Virtual Kubelet.

Procedure

In the configuration file of the pod, add the following annotation to specify the IP address of the NTP server that you want to use: k8s.aliyun.com/eci-ntp-server.

  1. Create a YAML file that is used to configure the NTP service.

    vim set-ntp-pod.yaml

    The content of the YAML file is:

    apiVersion: v1
    kind: Pod
    metadata:
      annotations:
        k8s.aliyun.com/eci-ntp-server: 10.10.5.1 # The IP address of the NTP server
      name: set-custom-ntp
    spec:
      nodeName: virtual-kubelet
      containers:
        - image: centos:latest
          command:
            - sleep
            - "3600"
          imagePullPolicy: IfNotPresent
          name: centos
  2. Apply the configurations in the YAML file to the pod.

    kubectl apply -f set-ntp-pod.yaml

Check the result

Log on the elastic container instance to check whether the NTP service works as expected.

  1. Query the information about the pod.

    kubectl get pod/set-custom-ntp

    Example:

    NAME                  READY   STATUS    RESTARTS   AGE
    set-custom-ntp   1/1         Running   0                 7m20s
  2. Go to the container.

    kubectl exec set-custom-ntp -it -- bash
  3. Query the source of the time of the container.

    chronyc sources

    If the IP address of the NTP server is returned, the NTP service works as expected. Example:

    210 Number of sources = 1
    MS Name/IP address         Stratum Poll Reach LastRx Last                            sample
    ===============================================================================
    ^* 10.10.5.1                    2           6     377     35       +40us[ +135us] +/-   14ms