kubernetes timezone in POD with command and argument

前端 未结 4 1823
醉酒成梦
醉酒成梦 2021-01-02 07:30

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

相关标签:
4条回答
  • 2021-01-02 08:00

    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 one of theses options:

    1. Add allowedHostPaths: {} next to volumes.
    2. Add TZ environment variable. For example: TZ = Asia/Jerusalem

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

    0 讨论(0)
  • 2021-01-02 08:02

    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.

    0 讨论(0)
  • 2021-01-02 08:10

    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
    
    0 讨论(0)
  • 2021-01-02 08:20

    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 
    
    0 讨论(0)
提交回复
热议问题