0

I am trying to update my pod time to Asia/Kolkata zone as per kubernetes timezone in POD with command and argument. However, the time still remains the same UTC time. Only the time zone is getting updated from UTC to Asia.

I was able to fix it using the volume mounts as below. Create a config map and apply the deployment yaml.

kubectl create configmap tz --from-file=/usr/share/zoneinfo/Asia/Kolkata -n <required namespace>

Why is the environmental variable method not working? Will a pod eviction occur from one host to another if we use volume mount time and will if affect the volume mount time after pod eviction?

The EV deployment YAML is below which does not update the time

apiVersion: apps/v1
kind: Deployment
metadata:
  name: connector
  labels:
    app: connector
  namespace: clients
spec:
  replicas: 1
  selector:
    matchLabels:
      app: connector
  template:
    metadata:
      labels:
        app: connector
    spec:
      containers:
      - image: connector
        name: connector
        resources:
          requests:
            memory: "32Mi"  # "64M"
            cpu: "250m"
          limits:
            memory: "64Mi"  # "128M"
            cpu: "500m"
        ports:
          - containerPort: 3307
            protocol: TCP
        env:
          - name: TZ
            value: Asia/Kolkata
        volumeMounts:
          - name: connector-rd
            mountPath: /home/mongobi/mongosqld.conf
            subPath: mongosqld.conf
      volumes:
      - name: connector-rd
        configMap:
          name: connector-rd
          items:
          - key: mongod.conf

Volume Mount yaml is below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: connector
  labels:
    app: connector
  namespace: clients
spec:
  replicas: 1
  selector:
    matchLabels:
      app: connector
  template:
    metadata:
      labels:
        app: connector
    spec:
      containers:
      - image: connector
        name: connector
        resources:
          requests:
            memory: "32Mi"  # "64M"
            cpu: "250m"
          limits:
            memory: "64Mi"  # "128M"
            cpu: "500m"
        ports:
          - containerPort: 3307
            protocol: TCP
        volumeMounts:
          - name: tz-config
            mountPath: /etc/localtime
          - name: connector-rd
            mountPath: /home/mongobi/mongosqld.conf
            subPath: mongosqld.conf
      volumes:
      - name: connector-rd
        configMap:
          name: connector-rd
          items:
          - key: mongod.conf
            path: mongosqld.conf
      - name: tz-config
        hostPath:
           path: /usr/share/zoneinfo/Asia/Kolkata
Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
Aniesh
  • 31
  • 1
  • 3
  • it happens only with kolkata? as per [this answer](https://stackoverflow.com/a/62641595/9929015), Europe/Warsaw works fine with the same example – Vit Jun 10 '21 at 09:54

2 Answers2

0

In this scenario you need to mention type attribute as File for hostPath in the deployment configuration. The below configuration should work for you.

 - name: tz-config
        hostPath:
           path: /usr/share/zoneinfo/Asia/Kolkata
           type: File
Kiruba
  • 1,322
  • 8
  • 15
0

Simply setting TZ env variable in deployment works for me