15.3. Consuming NFS exports in-cluster
Kubernetes application pods can consume NFS exports created by mounting a previously created PVC.
You can mount the PVC one of two ways:
Using a YAML:
Below is an example pod that uses the example PVC created in 15.2절. “Creating NFS exports”:
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
- <pvc_name>
-
Specify the PVC you have previously created, for example,
my-nfs-export.
Using the OpenShift Container Platform web console.
Procedure
-
On the OpenShift Container Platform web console, navigate to Workloads
Pods. - Click Create Pod to create a new application pod.
- Under the metadata section add a name. For example, nfs-export-example, with namespace as openshift-storage.
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/htmlFor 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/htmlUnder 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