Storage must exist in the underlying infrastructure before it can be mounted as
a volume in OpenShift Origin. To provision NFS volumes, a list of NFS servers and
export paths are all that is required.
You must first create an object definition for the PV:
Example 1. PV Object Definition Using NFS
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001 (1)
spec:
capacity:
storage: 5Gi (2)
accessModes:
- ReadWriteOnce (3)
nfs: (4)
path: /tmp (5)
server: 172.17.0.2 (6)
persistentVolumeReclaimPolicy: Recycle (7)
1 |
The name of the volume. This is the PV identity in various oc <command>
pod commands. |
2 |
The amount of storage allocated to this volume. |
3 |
Though this appears to be related to controlling access to the volume, it is
actually used similarly to labels and used to match a PVC to a PV. Currently, no
access rules are enforced based on the accessModes . |
4 |
The volume type being used, in this case the nfs plug-in. |
5 |
The path that is exported by the NFS server. |
6 |
The host name or IP address of the NFS server. |
7 |
The reclaim policy for the PV. This defines what happens to a volume when released
from its claim. Valid options are Retain (default) and Recycle. See
Reclaiming Resources. |
|
Each NFS volume must be mountable by all schedulable nodes in the cluster.
|
Save the definition to a file, for example nfs-pv.yaml, and create the PV:
$ oc create -f nfs-pv.yaml
persistentvolume "pv0001" created
Verify that the PV was created:
# oc get pv
NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON AGE
pv0001 <none> 5368709120 RWO Available 31s
The next step can be to create a persistent volume claim (PVC) which will bind
to the new PV:
Example 2. PVC Object Definition
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-claim1
spec:
accessModes:
- ReadWriteOnce (1)
resources:
requests:
storage: 1Gi (2)
1 |
As mentioned above for PVs, the accessModes do not enforce security, but
rather act as labels to match a PV to a PVC. |
2 |
This claim will look for PVs offering 1Gi or greater capacity. |
Save the definition to a file, for example nfs-claim.yaml, and create the
PVC:
# oc create -f nfs-claim.yaml