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
- From the OpenShift Web Console go to .
- Click Create Pod to create a new application pod.
- From the metadata section add a name. For example, nfs-export-example, with namespace as openshift-storage.
- Under the
spec:
section, addcontainers:
section withimage
andvolumeMounts
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
- Under the
spec:
section, addvolumes:
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