All Products
Search
Document Center

Specify time zones for pods

Last Updated: May 05, 2022

This topic describes how to configure different time zones for pods that run on Virtual Kubelet. When you deploy pods for an application, you can specify different time zones for the pods.

Prerequisites

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

Background information

The method that is used to update Virtual Kubelet varies based on the type of the Kubernetes cluster:

  • Serverless Kubernetes (ASK) cluster: You must contact the administrator to update Virtual Kubelet.

  • ACK managed cluster: You must manually update Virtual Kubelet.

  • ACK dedicated cluster: You must manually update Virtual Kubelet.

  • Self-managed cluster: You must manually update Virtual Kubelet.

Procedure

  1. Create a ConfigMap to import the time zone settings that you want to use.

    For other time zones, use the corresponding files in the /usr/share/zoneinfo/Asia/ directory. Example:

    kubectl create configmap tz --from-file=/usr/share/zoneinfo/Asia/Shanghai
  2. Create a YAML file to configure the time zone.

    vim set-timezone.yaml

    Mount the ConfigMap to the /etc/localtime/Shanghai directory. Example:

    apiVersion: v1
    kind: Pod
    metadata:
      name: timezone
    spec:
      containers:
      - name: timezone
        image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/busybox:1.30
        command: [ "sleep", "10000" ]
        volumeMounts:
          - name: tz
            mountPath: /etc/localtime
            subPath: Shanghai
      volumes:
        - name: tz
          configMap:
            name: tz
      nodeSelector:
        type: virtual-kubelet
      tolerations:
      - key: virtual-kubelet.io/provider
        operator: Exists
  3. Deploy a pod with the YAML file that you created.

    kubectl apply -f set-timezone.yaml

Verify the result

Log on to the container and check whether the time zone of the container is as you configured.

  1. Query information about the pod.

    kubectl get pod/timezone

    Expected output:

    NAME         READY   STATUS    RESTARTS   AGE
    timezone     1/1     Running   0          7m20s
  2. Log on to the container.

    kubectl exec timezone -it -- sh
  3. Query the time zone of the container.

    date -R

    If the time returned is consistent with the time zone that you configured, the time zone is configured for the container. Expected output:

    Fri, 01 May 2020 10:00:11 +0800