Persistent storage using hostPath

    OKD 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.

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

    Procedure

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

      1. apiVersion: v1
      2. kind: PersistentVolume
      3. metadata:
      4. name: task-pv-volume (1)
      5. labels:
      6. type: local
      7. spec:
      8. storageClassName: manual (2)
      9. capacity:
      10. storage: 5Gi
      11. accessModes:
      12. - ReadWriteOnce (3)
      13. persistentVolumeReclaimPolicy: Retain
    2. Create the PV from the file:

      1. apiVersion: v1
      2. kind: PersistentVolumeClaim
      3. metadata:
      4. name: task-pvc-volume
      5. spec:
      6. accessModes:
      7. - ReadWriteOnce
      8. resources:
      9. requests:
      10. storage: 1Gi
      11. storageClassName: manual
    3. Create the PVC from the file:

    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

      1. kind: Pod
      2. name: pod-name (1)
      3. spec:
      4. containers:
      5. ...
      6. securityContext:
      7. privileged: true (2)
      8. volumeMounts:
      9. - mountPath: /data (3)
      10. name: hostpath-privileged
      11. ...
      12. securityContext: {}
      13. volumes:
      14. - name: hostpath-privileged
      15. persistentVolumeClaim:
      16. claimName: task-pvc-volume (4)