Consuming NFS exports in-cluster

Kubernetes application pods can consume NFS exports created by mounting a previously created PVC.

Mount the PVCs either by using a YAML file or from the OpenShift Container Platform web console.

Mounting a PVC using a YAML file

This example uses the same example pod, used in the PVC creation example in Create NFS PVC using a YAML file, where <pvc_name> specifies the PVC you have previously created, for example, my-nfs-export.
apiVersion: v1
kind: Pod
metadata:
 name: nfs-export-example
spec:
 containers:
   - name: web-server
     image: nginx
     volumeMounts:
       - name: nfs-export-pvc
         mountPath: /var/lib/www/html
 volumes:
   - name: nfs-export-pvc
     persistentVolumeClaim:
       claimName: <pvc_name>
       readOnly: false

Mounting a PVC from the OpenShift Container Platform web console

  1. From the OpenShift Web Console go to Workloads > Pods.
  2. Click Create Pod to create a new application pod.
  3. From the metadata section add a name. For example, nfs-export-example, with namespace as openshift-storage.
  4. Under the spec: section, add containers: section with image and volumeMounts sections.
    apiVersion: v1
    kind: Pod
    metadata:
     name: nfs-export-example
     namespace: openshift-storage
    spec:
     containers:
       - name: web-server
         image: nginx
         volumeMounts:
           - name: <volume_name>
             mountPath: /var/lib/www/html
    For example:
    apiVersion: v1
    kind: Pod
    metadata:
     name: nfs-export-example
     namespace: openshift-storage
    spec:
     containers:
       - name: web-server
         image: nginx
         volumeMounts:
           - name: nfs-export-pvc
             mountPath: /var/lib/www/html
  5. Under the spec: section, add volumes: section to add the NFS PVC as a volume for the application pod.
    volumes:
      - name: <volume_name>
        persistentVolumeClaim:
          claimName: <pvc_name>
    For example:
    volumes:
      - name: nfs-export-pvc
        persistentVolumeClaim:
          claimName: my-nfs-export