# Configure a Pod to Use a PersistentVolume for Storage

Configure a Pod to Use a PersistentVolume for StorageThis page shows you how to configure a Pod to use a PersistentVolumeClaim for storage. Here is a summary of the process:You, as cluster administrator, create a PersistentVolume backed by physical storage. You do not associate the volume with any Pod.You, now taking the role of a developer / cluster user, create a PersistentVolumeClaim that is automatically bound to a suitable PersistentVolume.You create a Pod that uses the above PersistentVolumeClaim for storage.Before you beginYou need to have a Kubernetes cluster that has only one Node, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a single-node cluster, you can create one by using Minikube.Familiarize yourself with the material in Persistent Volumes.Create an index.html file on your NodeOpen a shell to the single Node in your cluster. How you open a shell depends on how you set up your cluster. For example, if you are using Minikube, you can open a shell to your Node by entering minikube ssh.In your shell on that Node, create a /mnt/data directory:# This assumes that your Node uses "sudo" to run commands # as the superuser sudo mkdir /mnt/data In the /mnt/data directory, create an index.html file:# This again assumes that your Node uses "sudo" to run commands # as the superuser sudo sh -c "echo 'Hello from Kubernetes storage' > /mnt/data/index.html" Note:If your Node uses a tool for superuser access other than sudo, you can usually make this work if you replace sudo with the name of the other tool.Test that the index.html file exists:cat /mnt/data/index.html The output should be:Hello from Kubernetes storage You can now close the shell to your Node.Create a PersistentVolumeIn this exercise, you create a hostPath PersistentVolume. Kubernetes supports hostPath for development and testing on a single-node cluster. A hostPath PersistentVolume uses a file or directory on the Node to emulate network-attached storage.In a production cluster, you would not use hostPath. Instead a cluster administrator would provision a network resource like a Google Compute Engine persistent disk, an NFS share, or an Amazon Elastic Block Store volume. Cluster administrators can also use StorageClasses to set up dynamic provisioning.Here is the configuration file for the hostPath PersistentVolume:pods/storage/pv-volume.yaml apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data" The configuration file specifies that the volume is at /mnt/data on the cluster's Node. The configuration also specifies a size of 10 gibibytes and an access mode of ReadWriteOnce, which means the volume can be mounted as read-write by a single Node. It defines the StorageClass name manual for the PersistentVolume, which will be used to bind PersistentVolumeClaim requests to this PersistentVolume.Note:This example uses the ReadWriteOnce access mode, for simplicity. For production use, the Kubernetes project recommends using the ReadWriteOncePod access mode instead.Create the PersistentVolume:kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml View information about the PersistentVolume:kubectl get pv task-pv-volume The output shows that the PersistentVolume has a STATUS of Available. This means it has not yet been bound to a PersistentVolumeClaim.NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE task-pv-volume 10Gi RWO Retain Available manual 4s Create a PersistentVolumeClaimThe