Setting Time Zone Synchronization
Case Scenarios
Scenario 1: Setting Time Zone Synchronization Between Containers and Nodes
- Log in to the CCE console.
- In the Basic Info area of the Create Workload 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 Basic Info area of the Create Workload 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 command 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 command 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.
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.
Example:
kind: Deployment apiVersion: apps/v1 metadata: name: test namespace: default spec: replicas: 2 selector: matchLabels: app: test template: metadata: labels: app: test spec: volumes: - name: vol-162979628557461404 hostPath: path: /etc/localtime type: '' containers: - name: container-0 image: 'nginx:alpine' volumeMounts: - name: vol-162979628557461404 readOnly: true mountPath: /etc/localtime imagePullPolicy: IfNotPresent imagePullSecrets: - name: default-secret
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot