簡體   English   中英

無法更改 kubernetes pod 的時區

[英]Can not change timezone for kubernetes pod

我正在嘗試修改 pod 的配置文件以使用本地時間,但在保存時顯示無效 你知道怎么回事嗎?

在 volumeMounts 部分:我添加了以下幾行:

- mountPath: /etc/localtime
      name: tz-config 

在卷設置中:我添加了以下幾行:

- name: tz-config
        hostPath:
          path: /usr/share/zoneinfo/Asia/Ho_Chi_Minh

這是我的 yaml 文件:

apiVersion: v1
kind: Pod
metadata:
  .....
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-jgznd
      readOnly: true  
    - mountPath: /etc/localtime
      name: tz-config            
  dnsPolicy: ClusterFirst
  .....
  volumes:
  - name: default-token-jgznd
    secret:
      defaultMode: 420
      secretName: default-token-jgznd
  - name: tz-config
    hostPath:
      path: /usr/share/zoneinfo/Asia/Ho_Chi_Minh   

更新:以下是錯誤詳細信息

# pods "hello-75fdf45c64-w7xm8" was not valid:
# * spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)
#   core.PodSpec{
#       Volumes: []core.Volume{
#               {Name: "default-token-wcf8m", VolumeSource: core.VolumeSource{Secret: &core.SecretVolumeSource{SecretName: "default-token-wcf8m", DefaultMode: &420}}},
# -             {
# -                     Name: "tz-config",
# -                     VolumeSource: core.VolumeSource{
# -                             HostPath: &core.HostPathVolumeSource{Path: "/usr/share/zoneinfo/Asia/Ho_Chi_Minh", Type: &""},
# -                     },
# -             },
#       },
#       InitContainers: nil,

我通過將 mountPath 添加到文件部署 yaml 解決了我的問題,如下所示。 非常感謝@Shawlz 的幫助:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2020-02-14T15:59:50Z"
  generation: 1
  labels:
    run: hello
  name: hello
  namespace: default
  resourceVersion: "523908"
  selfLink: /apis/apps/v1/namespaces/default/deployments/hello
  uid: 43196302-0176-4ce2-9d10-c8fefcc6c316
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: hello
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: hello
    spec:
      containers:
      - image: hello-microservice
        imagePullPolicy: Never
        name: hello
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
          - name: tz-config
            mountPath: /etc/localtime
      volumes:
        - name: tz-config
          hostPath:
            path: /usr/share/zoneinfo/Asia/Ho_Chi_Minh
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM