查看当前时间

## 通过命令查询 pod当前时间
# kubectl exec spring-boot-docker-image-test-deployment-7b5b58ff6c-4tmbk date -n test
> Mon Dec 10 14:48:58 UTC 2018

## 通过命令查看node机器的时间
# date 
> 2018年 12月 10日 星期一 22:49:43 CST

原因分析

## 通过对比时间,发现pod和node节点相差8小时
## 北京时间为东八区时间,因此怀疑node显示的北京时间(东八区),pod中为0时区时间
## 进入pod
# kubectl exec -ti spring-boot-docker-image-test-deployment-7b5b58ff6c-4tmbk -n pos  -- /bin/sh
# date -R
> Mon, 10 Dec 2018 14:56:16 +0000

## node节点执行
# date -R
> Mon, 10 Dec 2018 22:57:13 +0800

## 输出字符串的 +0000和+0800就是表示时区

修复

# 在Deployment添加volumes关于hostPath的配置
volumes:
- name: host-time
  hostPath:
    path: /etc/localtime
# 在Deployment添加containers.volumeMounts.mountPath
volumeMounts:
- name: host-time
  mountPath: /etc/localtime

具体文件如下

“` json
apiVersion: apps/v1beta1
kind: Deployment
metadata:
namespace: test
name: spring-boot-docker-image-test-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: spring-boot-docker-image-test
spec:
containers:
– name: spring-boot-docker-image-test
image: harbor.sunhaojie.comlibrary/spring_boot_docker_image_test:v001.001
volumeMounts:
– name: host-time
mountPath: /etc/localtime
imagePullPolicy: Always
imagePullSecrets:
– name: harbor.sunhaojie.com
volumes:
– name: host-time
hostPath:
path: /etc/localtime