Kubernetes - 容器的volumeMounts.mountPath 是否相对于PersistentVolume 的hostPath?

KJ0*_*797 0 kubernetes persistent-volumes

假设我创建了一个 hostPath 类型的 PersistentVolume:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: mypv
spec:
  storageClassName: normal
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /etc/foo  # Path on the host machine
Run Code Online (Sandbox Code Playgroud)

我创建相应的 PersistentVolumeClaim,并在 Pod 中使用它:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - image: busybox
    name: busybox
    volumeMounts:
    - name: myvolume
      mountPath: /var/log # is this relative to the hostPath of the PV?
  restartPolicy: Never
  volumes:
  - name: myvolume
    persistentVolumeClaim
      claimName: mypvc
status: {}
Run Code Online (Sandbox Code Playgroud)

预期结果是{hostPath}/{mountPath}(例如/etc/foo/var/log),还是我必须专门定义mountPath: /etc/foo/var/log才能得到它?

lar*_*sks 5

mountPath是容器内的安装点。它是从容器的文件系统根开始的绝对路径。如果mountPath/var/log,则该卷将安装在/var/log容器内部。

如果您有一个hostPath卷指向/etc/foo主机上并mountPath指向容器中,那么您将找到容器内可用/var/log的内容。/etc/foo/var/log

有关更多详细信息,请参阅文档