Persistent Volume:
PV
is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned
using Storage Classes
.
Persistent Volume Claim
PVC
is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs
consume PV
resources.
If you want to bound PV
and PVC
you can chose between two Provisioning ways:
A cluster administrator creates a number of PVs
. They carry the details of the real storage, which is available for use by cluster users. They exist in the Kubernetes API and are available for consumption.
When none of the static PVs
the administrator created match a user's PersistentVolumeClaim
, the cluster may try to dynamically provision a volume specially for the PVC
. This provisioning is based on StorageClasses:
the PVC
must request a storage class
and the administrator must have created and configured that class for dynamic provisioning to occur. Claims that request the class "" effectively disable dynamic provisioning for themselves.
In short, if you are using Static
provisioning, for each PVC
you need to create PV
, as they are bounding 1:1 relationship.
You can find more useful details in this thread.
As you are using Cloud environment (Amazon) which supports Dynamic Volume Provisioning you can just use PVC
. Dynamic Provisioning
will create PV
with PVC
requirements.
When you are using Statefulset
and you need to ensure that each pod will have own PV
, you can use VolumeClaimTemplate
like in documentation example.
Regarding main question:
How does the PVC get the storage from PV in the cluster? If I am running my service using Amazon cloud, what are the steps for the same, if any.
If you want to use static provisioning, you will need to create PV
and PVC
for each pod.
As most of the cloud provideres supports Dynamic Provisioning
you can just create PVC
and Cloud Provisioner will automatically creates PV
with PVC
requirements. In addition, the most common way to create PV
and PVC
for pods in statefulset
is to use VolumeClaimTemplate
, where you can specify storageclass, storage
and more other parameters:
volumeClaimTemplates:
- metadata:
name: cassandra-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: fast
resources:
requests:
storage: 1Gi