How to View and Access Persistent Volumes

Jonathan Peña
How to View and Access Persistent Volumes

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:

kubectl create clusterrolebinding pv-test --clusterrole=pv-reader --serviceaccount=web:default

The default service account in the web namespace is what will do this; it binds to the role pv-reader, which we just defined.

Creating a Pod to Access Persistent Volumes

Create Pod Definition: Create a YAML file named

apiVersion: V1
kind: Pod
metadata:
  name: curlpod
  namespace: web
spec:
  containers:
  - image: tutum/curl
    command: ["Sleep", "99999"]
    name: main
  - image: linuxacademycontent/kubectl-proxy
    name: proxy
  restartPolicy: Always

curlpod.yaml

  1. Apply the Pod Definition:
kubectl apply -f curlpod.yaml
  1. Verify the Pod is running:
kubectl get pod -n web
  1. Access the Pod: Open a new shell in the pod:
kubectl exec - it curlpod -n web -- sh
  1. Access the Persistent Volume: From within the pod, run:
curl: localhost:8001/api/v1/persistentvolume


Great! Next, complete checkout for full access to Cybersecurity
Welcome back! You've successfully signed in
You've successfully subscribed to Cybersecurity
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated