我正在尝试修改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: {}

08-28 13:55