一、通过环境变量设置
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: 2 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