k8s pod 时区更改
在K8S里启动一个容器,默认容器设置的时区是UTC 0,但是对于很多客户而言,其主机环境并不在UTC 0。例如中国客户在UTC8。如果不把容器的时区和主机设置为一致,则在查找日志等时候将非常不方便,也容易造成误解。
调整pod 容器时区的方法:
1、挂载服务器的时区
# 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:latest volumeMounts: - name: host-time mountPath: /etc/localtime readOnly: true volumes: - name: host-time hostPath: path: /etc/localtime
2、传递变量
# 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
参考文档:https://www.cnblogs.com/zhangb8042/p/11321970.html