#原生k8s pod 默認爲UTC,宿主爲CST
1、pod 與宿主 時間不一致
#解決辦法
1) 在dockerfile 中添加時區配置便可java
RUN rm -f /etc/localtime && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
2) pod與宿主共享時區文件nginx
apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: default labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 volumeMounts: - name: timezone mountPath: /etc/localtime # 掛載到容器的目錄 volumes: - name: timezone hostPath: path: /usr/share/zoneinfo/Asia/Shanghai # 宿主機的目錄
三、從新部署,此處使用dockerfiledocker
2、jvm 中也能夠經過參數方式使用CST時區api
java -jar -Duser.timezone=GMT+08 test.jar