同步pod时区与node主机保持一致

一、通过环境变量设置

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

二、通过挂载主机时区文件设置

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: myweb
spec:
replicas:
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: harbor/tomcat:8.5-jre8
volumeMounts:
- name: host-time
mountPath: /etc/localtime
ports:
- containerPort: 80
volumes:
- name: host-time
hostPath:
path: /etc/localtime

创建deployment后,找到pod,执行date命令检查时间是否同步

kubectl exec podid -- date

上一篇:js随机数的取整


下一篇:C 中读取键盘码