【问题标题】:Time Zone in Kubernetes Pods Using Environment VariableKubernetes Pod 中使用环境变量的时区
【发布时间】:2021-08-26 06:45:44
【问题描述】:

我正在尝试按照kubernetes timezone in POD with command and argument 将我的 pod 时间更新到亚洲/加尔各答区域。但是,时间仍然保持相同的 UTC 时间。只有时区从 UTC 更新到亚洲。

我能够使用如下的卷安装来修复它。创建配置映射并应用部署 yaml。

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

为什么环境变量方法不起作用?如果我们使用卷挂载时间,是否会从一台主机到另一台主机进行 pod 逐出,并且是否会影响 pod 逐出后的卷挂载时间?

EV 部署 YAML 下面不更新时间

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 如下。

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

【问题讨论】:

  • 它只发生在加尔各答?根据this answer,Europe/Warsaw 在同一个例子中工作得很好

标签: kubernetes timezone mongodb-biconnector


【解决方案1】:

在这种情况下,您需要在部署配置中为 hostPath 提及 type 属性作为 File。以下配置应该适合您。

 - name: tz-config
        hostPath:
           path: /usr/share/zoneinfo/Asia/Kolkata
           type: File

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-30
    • 2021-05-15
    • 1970-01-01
    • 2019-06-30
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多