All Products
Search
Document Center

Elastic Container Instance:Specify time zone

Last Updated:Nov 16, 2022

This topic describes how to specify time zones for pods.

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 an application that is used to configure the time zone.

    kubectl apply -f set-timezone.yaml

    The following code provides an example of timezone.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: timezone
      labels:
        app: test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: timezone
          labels:
            app: nginx
            alibabacloud.com/eci: "true" 
        spec:
          containers:
          - name: timezone
            image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
            volumeMounts:
              - name: tz
                mountPath: /etc/localtime   # The mount path.
                subPath: Shanghai       # Replace it based on your ConfigMap.
          volumes:
            - name: tz
              configMap: # Mount the ConfigMap.
                name: tz  

Verify the results

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

    The following command output is expected to return:

    NAME                        READY   STATUS    RESTARTS   AGE
    timezone-77cc64c57d-h59n8   1/1     Running   0          6
  2. Access the container.

    kubectl exec -it timezone-77cc64c57d-h59n8 -- 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. Example output:

    Wed, 19 Oct 2022 09:54:28 +0800