This topic describes how to specify different time zones for pods deployed on a virtual node.
Procedure
Create a ConfigMap and specify a time zone in the ConfigMap.
To specify a time zone, you need to import a ConfigMap from the /usr/share/zoneinfo/Asia/ directory. Example:
kubectl create configmap tz --from-file=/usr/share/zoneinfo/Asia/Shanghai
Create a YAML file to configure a time zone.
vim set-timezone.yaml
Mount the ConfigMap to the /etc/localtime/Shanghai directory. The following code block shows the content of a sample YAML file:
apiVersion: v1 kind: Pod metadata: name: timezone spec: containers: - name: timezone image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/busybox:1.30 command: [ "sleep", "10000" ] volumeMounts: - name: tz mountPath: /etc/localtime subPath: Shanghai volumes: - name: tz configMap: name: tz nodeSelector: type: virtual-kubelet tolerations: - key: virtual-kubelet.io/provider operator: Exists
Deploy a pod with the YAML file that you created.
kubectl apply -f set-timezone.yaml
Verify the configuration results
Log on to the container and check whether the time zone of the container is specified.
Query information about the pod.
kubectl get pod/timezone
Expected output:
NAME READY STATUS RESTARTS AGE timezone 1/1 Running 0 7m20s
Access the container.
kubectl exec timezone -it -- sh
Query the time zone of the container.
date -R
If the time returned is consistent with the time zone that you specified, the configuration is in effect. Expected output:
Fri, 01 May 2020 10:00:11 +0800
References
For more information about how to configure NTP for pods, see Configure NTP for pods.
For more information about ack-virtual-node, see ack-virtual-node.