How to change the timezone of containers running in k8s

  1. Change the timezone in the image(below commands needs to be modified according to the Linux distribution):
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Tehran /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

2. Change the timezone via k8s mount hostPath:

spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
name: nginx
volumeMounts:
- name: tz-config
mountPath: /etc/localtime
volumes:
- name: tz-config
hostPath:
path:  /usr/share/zoneinfo/Asia/Tehran

Leave a Comment