Persistent Volumes

Persistent Volumes

In this tutorial, we are going to discuss about Persistent Volumes in Kubernetes. When we created volumes in the previous tutorial, We configured volumes within the pod definition file so every configuration information required to configure storage for the volume goes within the POD definition file.

Now when you have a large environment with a lot of users deploying a lot of PODs, the users would have to configure storage every time for each POD.

Whatever storage solution is used the users who deploys the PODs would have to configure that on all pod definition files in his own environment.

Every time it changes to be made, The user would have to make them on all of his PODs. Instead you would like to manage storage more centrally.

Persistent Volumes

A Persistent Volume is a cluster-wide pool of storage volumes configured by an administrator to be used by users deploying application on the cluster. The users can now select storage from this pool using Persistent Volume Claims.

Let us now create a persistent volume.

kind: PersistentVolume
apiVersion: v1
  name: pv-vol
  accessModes: [ "ReadWriteOnce" ]
   storage: 1Gi
    path: /home/ashok/data

Here accessModes defines how a volume should be mounted on the hosts whether in a read only mode or read write mode etc. The supported values are

  1. ReadOnlyMany
  2. ReadWriteOnce
  3. ReadWriteMany

Next is the capacity. Here we have to specify the amount of storage to be reserved for this persistent volume which is set to 1 GB here.

Next comes the volume type. We will start with the host path option that uses storage from the nodes local directory. Remember this option is not to be used in a production environment.

To create the persistent volume run the following command

$ kubectl create -f pv-definition.yaml
persistentvolume/pv-vol created

To list the persistent volumes run the following command

$ kubectl get pv
pv-vol   1Gi        RWO            Retain           Available                                   3min

Now to delete the persistent volume run the following command

$ kubectl delete pv pv-vol
persistentvolume "pv-vol" deleted
Persistent Volumes

Scroll to top