All Products
Search
Document Center

Configure NTP for pods

Last Updated: Mar 18, 2022

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 updated to the latest version. For more information, see Update Virtual Kubelet.

Background information

The operations for updating Virtual Kubelet vary based on the type of Kubernetes cluster that you use.

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

  • Container Service for Kubernetes (ACK) clusters include ACK managed clusters and ACK dedicated clusters. For ACK managed clusters, the system automatically updates Virtual Kubelet. For ACK dedicated clusters, you must manually update Virtual Kubelet.

  • For self-managed clusters that are deployed on Elastic Compute Service (ECS) instances or on-premises clusters, you must manually update Virtual Kubelet.

Procedure

Add the k8s.aliyun.com/eci-ntp-server annotation to the pod. The annotation specifies the IP address of the NTP server that you want to use.

  1. Create a YAML file to configure the NTP service.

    vim set-ntp-pod.yaml

    The YAML file contains the following content:

    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. Use the configurations in the YAML file for the pod.

    kubectl apply -f set-ntp-pod.yaml

Verify the result

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

  1. Query the information about the pod.

    kubectl get pod/set-custom-ntp

    Expected output:

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

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

    chronyc sources

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

    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