Let's say I create a PersistentVolume of type hostPath:
kind: PersistentVolume
apiVersion: v1
metadata:
name: mypv
spec:
storageClassName: normal
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: /etc/foo # Path on the host machine
and I create the corresponding PersistentVolumeClaim, and use it in a 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: {}
Is it expected that the result would be {hostPath}/{mountPath}
(e.g. /etc/foo/var/log
), or would I have to specifically define mountPath: /etc/foo/var/log
to get it there?
The mountPath
is the mountpoint inside the container. It is an absolute path starting at the container's filesystem root. If mountPath
is /var/log
, then the volume will be mounted on /var/log
inside the container.
If you have a hostPath
volume pointing at /etc/foo
on the host and mountPath
pointing at /var/log
in the container, then you will find the contents of /etc/foo
available inside /var/log
inside the container.
For more details, see the documentation.