Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to set Pod time zone in Kubernetes

Shulou Source: shulou.com Published: 2022-06-01 17:30:07 09月30日 Update

This article shows you how to set the Pod time zone in Kubernetes, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Containers running in a kubernetes cluster use Greenwich time by default, that is, when Beijing time is 12:00, the container time is 4 o'clock, while some distributed systems are extremely time-sensitive and do not allow time errors.

In order to keep the container time synchronized with the host time, you can use hostPath to mount the time zone files on the host to the container.

For example, if the time zone of the current host is Asia/Shanghai, a link to / usr/share/zoneinfo/Asia/Shanghai will be displayed when using ll / etc/localtime

[root@localhost ~] # ll / etc/localtime

Lrwxrwxrwx. 1 root root 35 Jul 12 14:26 / etc/localtime->.. / usr/share/zoneinfo/Asia/Shanghai

If you need the system to modify the time zone, you only need to overwrite the time zone file to / etc/localtime, as shown in

[root@localhost ~] # cp-f / usr/share/zoneinfo/ {{time zone file}} / etc/localtime

The time zone in the container is updated in the same way, such as the following example:

-apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginxspec: template: metadata: labels: app: nginxspec: containers:-name: nginx image: 'nginx:latest' imagePullPolicy: IfNotPresent resources: requests: cpu: 100m memory: 100Mi ports:-containerPort: 80 VolumeMounts:-name: timezone mountPath: / etc/localtime volumes:-name: timezone hostPath: path: / usr/share/zoneinfo/Asia/Shanghai

This is equivalent to setting the Shanghai time zone for the nginx container, so that the time in the container will be consistent with the host. Of course, other methods can be used, as long as the time zone file can be updated to / etc/localtime.

The above is how to set the Pod time zone in Kubernetes. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Time zone time container host file host content skills methods knowledge systems updates concise consistent concise examples distributed that is articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL NVidia Apple Xiaomi