You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]
You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

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.


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 StorageClasses to set up dynamic provisioning.

A hostPath volume must be provisioned statically.

Statically provisioning hostPath volumes

A Pod that uses a hostPath volume must be referenced by manual (static) provisioning.

  1. Define the persistent volume (PV). Create a file, pv.yaml, with the PersistentVolume object definition:

      apiVersion: v1
      kind: PersistentVolume
        name: task-pv-volume (1)
          type: local
        storageClassName: manual (2)
          storage: 5Gi
          - ReadWriteOnce (3)
        persistentVolumeReclaimPolicy: Retain
          path: "/mnt/data" (4)
    1 The name of the volume. This name is how it is identified by PersistentVolumeClaims or Pods.
    2 Used to bind PersistentVolumeClaim requests to this PersistentVolume.
    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.
  2. Create the PV from the file:

    $ oc create -f pv.yaml
  3. Define the persistent volume claim (PVC). Create a file, pvc.yaml, with the PersistentVolumeClaim object definition:

    apiVersion: v1
    kind: PersistentVolumeClaim
      name: task-pvc-volume
        - ReadWriteOnce
          storage: 1Gi
      storageClassName: manual
  4. Create the PVC from the file:

    $ oc create -f pvc.yaml

Mounting the hostPath share in a privileged Pod

After the PersistentVolumeClaim has been created, it can be used inside by an application. The following example demonstrates mounting this share inside of a Pod.

  • A PersistentVolumeClaim exists that is mapped to the underlying hostPath share.

  • Create a privileged Pod that mounts the existing PersistentVolumeClaim:

    apiVersion: v1
    kind: Pod
      name: pod-name (1)
          privileged: true (2)
        - mountPath: /data (3)
          name: hostpath-privileged
      securityContext: {}
        - name: hostpath-privileged
            claimName: task-pvc-volume (4)
    1 The name of the Pod.
    2 The Pod must run as privileged to access the node’s storage.
    3 The path to mount the hostPath share inside the privileged Pod.
    4 The name of the PersistentVolumeClaim that has been previously created.