kubernetes timezone in POD with command and argument

3/10/2019

I want to change timezone with command. I know applying hostpath.

Could you know how to apply command ?

ln -snf /user/share/zoneinfor/$TZ /etc/localtime

it works well within container. But I don't know applying with command and arguments in yaml file.

-- canerbis
command
kubernetes
timezone
yaml

3 Answers

4/30/2020

In order to add "hostPath" in the deployment config, as suggested in previous answers, you'll need to be a privileged user. Otherwise your deployment may fail on:

"hostPath": hostPath volumes are not allowed to be used

As a workaround you can try to add allowedHostPaths: {} next to volumes.

Note that on Openshift containers, there's another way to set the time-zone, simply by adding a new environment variable TZ. For example:

TZ = Asia/Jerusalem

(This is similar to running docker exec -it openshift/origin /bin/bash -c "export TZ='Asia/Jerusalem' && /bin/bash").

-- Noam Manos
Source: StackOverflow

3/11/2019

You can change the timezone of your pod by using specific timezone config and hostPath volume to set specific timezone. You're yaml file will look something like:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-sleep
spec:
  containers:
  - name: busybox
    image: busybox
    args:
    - sleep
    - "1000000"
    volumeMounts:
    - name: tz-config
      mountPath: /etc/localtime
  volumes:
    - name: tz-config
      hostPath:
        path: /usr/share/zoneinfo/Europe/Prague
        type: File

If you want it across all pod, deployment you need to add volume and volumeMounts to all your deployment file and change the path value in hostPath section to the timezone you want to set.

-- Prafull Ladha
Source: StackOverflow

5/28/2019

In a deployment, you can do it by creating a volumeMounts in /etc/localtime and setting its values. Here is an example I have for a mariadb:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mariadb
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
        - name: mariadb
          image: mariadb
          ports:
            - containerPort: 3306
              name: mariadb
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: password
          volumeMounts:
          - name: tz-config
            mountPath: /etc/localtime
      volumes:
      - name: tz-config
        hostPath:
           path: /usr/share/zoneinfo/Europe/Madrid 
-- pcampana
Source: StackOverflow