Kubernetes Persistent Volumes
Introduction
Managing storage is a distinct problem from managing compute instances. The PersistentVolume subsystem provides an API for users and administrators that abstracts details of how storage is provided from how it is consumed. To do this, we introduce two new API resources: PersistentVolume and PersistentVolumeClaim.
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.
A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted ReadWriteOnce, ReadOnlyMany or ReadWriteMany, see AccessModes).
While PersistentVolumeClaims allow a user to consume abstract storage resources, it is common that users need PersistentVolumes with varying properties, such as performance, for different problems. Cluster administrators need to be able to offer a variety of PersistentVolumes that differ in more ways than size and access modes, without exposing users to the details of how those volumes are implemented. For these needs, there is the StorageClass resource.
Create NFS Persistent Volume
- Setup for this example
- Create YAML file for PVD configuration
- Apply the changes
- Check PV Status
- Create YAML file for PVC configuration
- Apply the changes
- Check PVC Status
- Create YAML file for POD configuration
- Apply the changes
- Check POD Status
- Run following command to access content of persisten storage
Prerequisite: Make sure NFS server is reachable from worker nodes and try to mount nfs share on each worker once for testing.
PV Name : task-nfs-pv
PVC Name : task-nfs-pvc
POD Name : task-nginx-pv-pod
NFS Share : 192.168.50.10:/repo/exports
NFS Share Content: Create /repo/exports/index.html file in NAS share and put below string to be validated later on. SUCCES: Hello from Kubernetes NFS volume