Setting Time Zone Synchronization
Case Scenarios
- Scenario 1: Setting Time Zone Synchronization Between Containers and Nodes
- Scenario 2: Setting Time Zone Synchronization Among Containers, Container Logs, and Nodes
- Scenario 3: Setting Time Zone Synchronization Between Workloads and Nodes
- Scenario 4: Changing the Time Zone of a Node in the Cluster of an Earlier Version
Scenario 1: Setting Time Zone Synchronization Between Containers and Nodes
- Log in to the CCE console. In the navigation pane on the left, choose Workloads > Deployments or Workloads > StatefulSets. Click Create Deployment or Create StatefulSet.
- On the Specify Basic Info page, enable Time Zone Synchronization so that the same time zone will be used for both the container and the node. Figure 1 Enabling the time zone synchronization
- Log in to the node, go to the container, and check whether the time zone of the container is the same as that of the node.
date -R
Information similar to the following is displayed:
Tue, 04 Jun 2019 15::08:47 +0800
docker ps -a|grep test
Information similar to the following is displayed:

docker exec -it oedd74c66bdb /bin/sh
date -R
Information similar to the following is displayed:
Tue, 04 Jun 2019 15:09:20 +0800
Scenario 2: Setting Time Zone Synchronization Among Containers, Container Logs, and Nodes
The difference between the time when the Java application prints logs and the container's standard time obtained in date -R mode is 8 hours.
- Log in to the CCE console. In the navigation pane on the left, choose Workloads > Deployments or Workloads > StatefulSets. Click Create Deployment or Create StatefulSet.
- On the Specify Basic Info page, enable Time Zone Synchronization so that the same time zone will be used for both the container and the node. Figure 2 Enabling the time zone synchronization
- Log in to the node, go to the container, and modify the catalina.sh script.
cd /usr/local/tomcat/bin
vi catalina.sh
If you cannot run the vi command in the container, go to 4 or run the vi command to add -Duser.timezone=GMT+08 to the script, as shown in the following figure.

- Copy the script from the container to the node, add -Duser.timezone=GMT+08 to the script, and then copy the script from the node to the container.
Run the following commands to copy files in the container to the host machine:
docker cp mycontainer: /usr/local/tomcat/bin/catalina.sh /home/catalina.sh
Run the following commands to copy files from the host machine to the container:
docker cp /home/catalina.sh mycontainer:/ usr/local/tomcat/bin/catalina.sh
- Restart the container.
docker restart container_id
- Check whether the time zone of the logs is the same as that of the node. On the CCE console, click the workload name. On the workload details page displayed, click Logs in the upper right corner to view the log details. It takes about 5 minutes to load the logs.Figure 3 Viewing workload logs
Scenario 3: Setting Time Zone Synchronization Between Workloads and Nodes
- Method 1: Set the time zone to CST when creating a container image.
- Method 2: If you do not want to modify the container, when creating a workload on the CCE console, mount the /etc/localtime directory of the local host to the /etc/localtime directory of the container. The detailed procedure is as follows:
- When creating a workload, click Data Storage and then click Add Local Volume.
- Select HostPath for Type, set Host Path to /etc/localtime, Container Path to /etc/localtime, and Permission to Read-only, leave subPath unspecified, and click OK. Figure 4 Adding a local volume
Scenario 4: Changing the Time Zone of a Node in the Cluster of an Earlier Version
Symptom
The time zone of the node managed by the user is the UTC time zone by default.
Solution
In clusters of an earlier version (v1.7.3-r10 or earlier), the UTC time zone is used by default when nodes are managed. In clusters of later versions (v1.9.2-r1), the time zone has been changed to the local time zone.
Perform the following steps to change the time zone of the node to the local time zone:
- Upgrade the cluster. After the cluster is upgraded to the latest version, all nodes in the cluster automatically switch to the local time zone.
- Log in to the CCE console. In the navigation pane, choose Resource Management > Clusters.
- Click More for the cluster you want to upgrade, and select Upgrade from the drop-down menu.
Then, upgrade the cluster as prompted.
If you do not want to upgrade the cluster, perform the following steps to manually change the time zone of the node:
- (Optional) Log in to each node and manually change the time zone.
- Log in to the node whose time zone is to be changed as user root.
- Obtains the time zone information.
TIME_ZONE=`cat /var/paas/conf/cluster.conf | python -m json.tool | grep '\"timezone\":' | awk -F '"' '{print $4}'`; echo $TIME_ZONE;
- Change the time zone of the current node to the time zone specified by $TIME_ZONE.
ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
- Check whether the time zone has taken effect:
- Repeat the preceding steps to change the time zone of other nodes in the cluster.
Last Article: Initializing a Container
Next Article: Performing Graceful Deletion
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.