Setting Time Zone Synchronization
Case Scenarios
Scenario 1: Setting Time Zone Synchronization Between Pods 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 pod and the node. After completing other settings, create the workload.
Figure 1 Enabling the time zone synchronization
- Log in to the node and obtain the time zone.
date -R
Information similar to the following is displayed:
Sat, 12 Apr 2025 16:58:47 +0800
- Check whether the time zone of the pod is the same as that of the node.
Run the following kubectl command to obtain the pod name:
kubectl get pod
Run the kubectl command to access the pod. In the command, <pod_name> specifies the pod name obtained in the previous step.
kubectl exec -it <pod_name> -- /bin/bash
Obtain the time zone of the pod.
date -R
Information similar to the following is displayed:
Sat, 12 Apr 2025 16:59:23 +0800
Scenario 2: Setting Time Zone Synchronization Between Java Container Logs, Pods, and Nodes
After time zone synchronization between a pod and the host node is enabled, the standard time inside the pod (obtained by running date -R) aligns with the node time. However, a Java application uses the default time zone, leading to discrepancies between the time recorded in logs and the pod time. The following uses a Java application that runs in a Tomcat container as an example to describe how to synchronize the time zone in the Java container logs with the node time zone.
- 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 pod and the node.
Figure 2 Enabling the time zone synchronization
- In the Container Settings area, click Environment Variables and add the following environment variable:
- Environment variable name: CATALINA_OPTS
- Environment variable value: -Duser.timezone=GMT+08
- After completing the configuration, create the workload.
- In the workload list, locate the row containing the workload, click View Log in the Operation column, and check whether the time zone in the logs is the same as that of the pod and node. For details about how to check the time zone of a node and pod, see Scenario 1: Setting Time Zone Synchronization Between Pods and Nodes.
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