This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.3.8. Persistent storage using hostPath
A hostPath volume in an OpenShift Container Platform cluster mounts a file or directory from the host node’s filesystem into your pod. Most pods will not need a hostPath volume, but it does offer a quick option for testing should an application require it.
The cluster administrator must configure pods to run as privileged. This grants access to pods in the same node.
3.8.1. Overview 复制链接链接已复制到粘贴板!
OpenShift Container Platform supports hostPath mounting for development and testing on a single-node cluster.
In a production cluster, you would not use hostPath. Instead, a cluster administrator would provision a network resource, such as a GCE Persistent Disk volume, an NFS share, or an Amazon EBS volume. Network resources support the use of storage classes to set up dynamic provisioning.
A hostPath volume must be provisioned statically.
3.8.2. Statically provisioning hostPath volumes 复制链接链接已复制到粘贴板!
A pod that uses a hostPath volume must be referenced by manual (static) provisioning.
Procedure
Define the persistent volume (PV). Create a file,
pv.yaml
, with thePersistentVolume
object definition:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The name of the volume. This name is how it is identified by persistent volume claims or pods.
- 2
- Used to bind persistent volume claim requests to this persistent volume.
- 3
- The volume can be mounted as
read-write
by a single node. - 4
- The configuration file specifies that the volume is at
/mnt/data
on the cluster’s node.
Create the PV from the file:
oc create -f pv.yaml
$ oc create -f pv.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the persistent volume claim (PVC). Create a file,
pvc.yaml
, with thePersistentVolumeClaim
object definition:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the PVC from the file:
oc create -f pvc.yaml
$ oc create -f pvc.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.8.3. Mounting the hostPath share in a privileged pod 复制链接链接已复制到粘贴板!
After the persistent volume claim has been created, it can be used inside by an application. The following example demonstrates mounting this share inside of a pod.
Prerequisites
- A persistent volume claim exists that is mapped to the underlying hostPath share.
Procedure
Create a privileged pod that mounts the existing persistent volume claim:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow