1

I need to deploy an application that have Europe/Rome timezone.

I applied the following deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: 10.166.23.73:5000/local/myapp:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          env:
            - name: TZ
              value: Europe/Rome
          volumeMounts:
          - name: tz-rome
            mountPath: /etc/localtime
      volumes:
        - name: tz-rome
          hostPath:
            path: /usr/share/zoneinfo/Europe/Rome

However, when I run "date" command within the POD, I don't get the "Europe/Rome" timezone...

What is wrong with the above deployment yaml?

mark009
  • 33
  • 4
  • https://stackoverflow.com/questions/55089265/kubernetes-timezone-in-pod-with-command-and-argument – R10t-- Feb 03 '22 at 16:05

1 Answers1

4

If you remove the env variable, that should be works. for example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: test-timezone
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: busybox
          imagePullPolicy: Always
          command: [ "sleep", "10000" ]
          volumeMounts:
          - name: tz-rome
            mountPath: /etc/localtime
      volumes:
        - name: tz-rome
          hostPath:
            path: /usr/share/zoneinfo/Europe/Rome

The output:

/ # date
Fri Feb  4 02:16:16 CET 2022

If you want to set the timezone using TZ environment, you need the tzdata package in the container, for example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp3
  namespace: test-timezone
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: nginx
          imagePullPolicy: Always
          command: [ "sleep", "10000" ]
          env:
            - name: TZ
              value: Europe/Rome

Nginx has the tzdata package inside:

root@myapp2-6f5bbdf56-nnx66:/# apt list --installed | grep tzdata

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

tzdata/now 2021a-1+deb11u2 all [installed,local]

root@myapp2-6f5bbdf56-nnx66:/# date
Fri Feb  4 02:32:48 CET 2022
jitapichab
  • 129
  • 4