全部产品
Search
文档中心

容器服务 Kubernetes 版 ACK:为Pod配置NTP服务

更新时间:Jan 10, 2024

如果您希望部署在Virtual Node上的Pod内的容器能与NTP服务进行时间同步,您可以为Pod配置NTP服务。

操作步骤

您需要在Pod的Annotations中增加k8s.aliyun.com/eci-ntp-server注解,设置需要配置的NTP服务的IP地址。

  1. 创建配置NTP服务的YAML文件。

    vim set-ntp-pod.yaml

    以下为YAML文件的内容示例:

    apiVersion: v1
    kind: Pod
    metadata:
      annotations:
        k8s.aliyun.com/eci-ntp-server: 10.10.5.1  # 设置您的NTP服务的IP地址。
      name: set-custom-ntp
    spec:
      nodeName: virtual-kubelet
      containers:
        - image: centos:latest
          command:
            - sleep
            - "3600"
          imagePullPolicy: IfNotPresent
          name: centos
  2. 将YAML文件中的配置应用到Pod。

    kubectl apply -f set-ntp-pod.yaml

验证结果

登录到容器,验证NTP服务是否设置成功。

  1. 获取Pod信息。

    kubectl get pod/set-custom-ntp

    返回示例如下:

    NAME                  READY   STATUS    RESTARTS   AGE
    set-custom-ntp   1/1         Running   0                 7m20s
  2. 进入容器。

    kubectl exec set-custom-ntp -it -- bash
  3. 查询容器的时间来源。

    chronyc sources

    如果返回了NTP服务的IP地址,则表示设置成功。返回示例如下:

    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 

相关文档