This procedure shows how to configure a Workload to use a Persistent Volume Claim (PVC) to access your NFS shared storage.
Before you begin
The following items and configurations are required for this procedure:
Kubernetes version 1.15.x or higher
Konvoy version 1.4.x or higher
NFS shared storage in your environment and accessible to your cluster
Valid Persistent Volume installed
Persistent Volume Claim installed and in the pending state
Create a Pod that uses a Persistent Volume Claim
If a workload does not claim a Persistent Volume Claim it stays in a
Pending state. This procedure shows how to create an example workload that claims and uses the Persistent Volume Claim (PVC). This procedure also validates that the workload can access the volume.
Create a file called
nfs-app.yaml, similar to the example below.
kind: Pod apiVersion: v1 metadata: name: pod-nfs spec: containers: - name: nfs-app image: alpine volumeMounts: null - name: data mountPath: /var/nfs # The path in you container where the NFS shared volume is available. command: - /bin/sh args: - '-c' - sleep 500000 volumes: - name: data persistentVolumeClaim: claimName: nfs-pvc # The name of the PVC you want to use in this pod.
mountPathwith the path in the container that maps to your NFS Share. You can change this to any path in your container.
Configure the `claimName’ with the name of the Persistent Volume Claim you want to use.
Next, apply the file.
kubectl apply -f nfs-app.yaml
After the file is deployed, you should receive a return value of
Ensure that it is fully deployed.
kubectl get pod pod-nfs
When the container is fully running and the
Running, you should see output similar to the following:
NAME READY STATUS RESTARTS AGE pod-nfs 1/1 Running 0 2m27s
Use the following command to validate that the PVC has mounted the volume to your container
kubectl describe pod pod-nfs
You can see under the describe conditions that the Persistent Volume Claim has been mounted to your container under the
ClaimName: nfs-pvcwhich is the PVC.
Volumes: null data: Type: >- PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) ClaimName: nfs-pvc ReadOnly: false
Enter the following command to validate that, inside the container, we can access the volume and write data:
kubectl exec -it pod-nfs sh
This is where the
mountPath: /var/nfswas labeled in the
pod-nfs.yaml. If you change the value,
cd to your path.
If you can access your
mountPath, you have successfully mounted the NFS volume to your container. Now try and write a file into the volume.
Enter the following command to create a file in the directory and list all files in that same directory.
touch nfs.txt && ls
You should see a file called
nfs.txt. If you do, you have a fully functional NFS volume accessible to your container.
For information on related topics or procedures, refer to the following: