Rancher entry to the master zone when the container -2.0 K8S autoconfiguration -Pod Preset

 

By default, the internal Pod K8S cluster control zone is UTC0, the area is inconsistent with where we actually can cause a problem logging and other aspects. The interior of the container it is necessary to host (node ​​node) is consistent with time. Want solution of this problem are the following ideas.

Docker level time zone settings

The first idea is to complete from the time zone settings docker level, which is implemented in two ways, which are done by the host environment variables and mount papers. In the following manner required to ensure that the current time zone of the host is configured correctly.

1, the time zone setting environment variables container

By the time the container starts, set the environment variable TZ=Asia/Shanghaito implement ways:

docker run --name=centos -e "TZ=Asia/Shanghai" centos

2, the time zone of the host to mount a file into the container

By starting the container, loading the time zone /etc/localtimedata volume way to achieve:

docker run --name=centos -v /etc/localtime:/etc/localtime:ro centos

Also, if the image is automatically packaged, can be defined Hershey zone environment variables dockerfile file, generate a new image.

K8S level time zone settings

In K8S cluster, may be set with reference to the time zone docker manner.

1, set the environment variable

apiVersion: v1
kind: Pod
metadata:
  name: pod-env-tz
spec:
  containers:
  - name: mynginx
    image: nginx:latest
    imagePullPolicy: IfNotPresent
    env:
      - name: TZ
        value: Asia/Shan

Guess you like

Origin blog.csdn.net/wxb880114/article/details/103676720