Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes timezone in POD with command and argument

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.

like image 460
canerbis Avatar asked Mar 10 '19 15:03

canerbis


People also ask

How do you use commands and arguments in Kubernetes?

Define a command and arguments when you create a PodTo define a command, include the command field in the configuration file. To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created.


2 Answers

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.

like image 68
Prafull Ladha Avatar answered Sep 22 '22 18:09

Prafull Ladha


Setting TZ environment variable as below works fine for me on GCP Kubernetes.

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
spec:
  replicas: 1
  selector:
    matchLabels:
        app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: demo
        image: gcr.io/project/image:master
        imagePullPolicy: Always
        env:
            - name: TZ
              value: Europe/Warsaw
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 0
like image 22
warden Avatar answered Sep 22 '22 18:09

warden