5.3.2. Statically provisioning hostPath volumes
Statically provision hostPath volumes by creating a persistent volume (PV) that maps to a path on the host node’s filesystem, then creating a persistent volume claim (PVC) that binds to the PV. Dynamic provisioning is not supported for hostPath volumes.
A pod that uses a hostPath volume must be referenced by manual (static) provisioning.
Procedure
Define the persistent volume (PV) by creating a
pv.yamlfile with thePersistentVolumeobject definition:apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain hostPath: path: "/mnt/data"-
metadata.name: Specifies the name of the volume. This name is how the volume is identified by persistent volume (PV) claims or pods. -
spec.storageClassName: The storage class is used to bind persistent volume claim (PVC) requests to the PV. -
spec.accessModes: Specifies the access mode. The volume can be mounted asread-writeby a single node. -
spec.hostPath.path: The configuration file specifies that the volume is at/mnt/dataon the cluster’s node. To avoid corrupting your host system, do not mount to the container root,/, or any path that is the same in the host and the container. You can safely mount the host by using/host
-
Create the PV from the file:
$ oc create -f pv.yamlDefine the PVC by creating a
pvc.yamlfile with thePersistentVolumeClaimobject definition:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: task-pvc-volume spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: manualCreate the PVC from the file:
$ oc create -f pvc.yaml