What are Persistent Volumes (PVs)?
PV is a method for defining storage-related data, like storage classes and storage implementations. In a Kubernetes cluster, PVs are resource objects similar to storage resource objects; they are not the same as regular volumes.
Persistent volume claims (PVC) must be used to request this resource. A PV is mounted into a Pod using a PVC volume, which is a request for storage. Different classes can be mapped to different backend policies and service levels by the cluster administrator.
You can define the plugin type to utilize and carry out persistent storage volume through the YAML configuration file. The persistent storage volume configuration file in YAML format is as follows. 5Gi of storage space must be made available for this configuration file. ReadWriteOnce is the access method, Filesystem is the storage mode, and the Recycling recycling policy recycles the persistent storage volume. In conclusion, a slow storage class is designated, and the NFS plug-in type is employed.
Now lets head on over to the LAB:
Step 1: Revise persistent volumes:
kubectl get pv
Step 2: Creating a Custom Role to View Persistent Volumes:
kubectl create clusterrole pv-reader --verb=get,list --resource=persistentvolumes
Step 3: List the created role:
kubectl get clusterrole
Creating Cluster Role Binding
To bind the pv-reader
role to a service account:
Creating a Pod to Access Persistent Volumes
Create Pod Definition: Create a YAML file named
- Apply the Pod Definition:
kubectl apply -f curlpod.yaml
- Verify the Pod is running:
kubectl get pod -n web
- Access the Pod: Open a new shell in the pod:
kubectl exec - it curlpod -n web -- sh
- Access the Persistent Volume: From within the pod, run:
curl: localhost:8001/api/v1/persistentvolume