k8s pod时区更改

一、问题所在

在K8S里启动一个容器,该容器的设置的时区是UTC0,但是对于很多客户而言,其主机环境并不在UTC0。例如中国客户在UTC8。如果不把容器的时区和主机主机设置为一致,则在查找日志等时候将非常不方便,也容易造成误解。

二、解决方法

1、挂载服务器的时区

[root@k8s-m ~]# cat demo-pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  namespace: default
  labels: 
    app: my-pod
     
spec:
  containers:
  - name: my-pod
    image: nginx
    volumeMounts:
      - name: host-time
        mountPath: /etc/localtime
        readOnly: true
  volumes:
    - name: host-time
      hostPath: 
        path: /etc/localtime

2、传递变量

[root@k8s-m ~]# cat time-pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: pod-env-tz
spec:
  containers:
  - name: ngx-time
    image: nginx:latest
    env:
      - name: TZ
        value: Asia/Shanghai

3、重新构建镜像,做镜像是把镜像的时区改了就行

4、修改apiserver的配置清单,用Pod Pres方式更改所有容器的时区(看了好多个文档,试了多次,都没成功)

猜你喜欢

转载自www.cnblogs.com/zhangb8042/p/11321970.html