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
Define the persistent volume (PV). Create a file,
pv.yaml
, with thePersistentVolume
object definition:apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume (1)
labels:
type: local
spec:
storageClassName: manual (2)
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce (3)
persistentVolumeReclaimPolicy: Retain
Create the PV from the file:
-
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pvc-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: manual
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
-
kind: Pod
name: pod-name (1)
spec:
containers:
...
securityContext:
privileged: true (2)
volumeMounts:
- mountPath: /data (3)
name: hostpath-privileged
...
securityContext: {}
volumes:
- name: hostpath-privileged
persistentVolumeClaim:
claimName: task-pvc-volume (4)