1️. What is a Persistent Volume (PV)?
A Persistent Volume (PV) is a provisioned storage resource that administrators configure in the cluster. It can be backed by local storage, cloud storage (AWS EBS, Azure Disk, GCE Persistent Disk), or network storage (NFS, Ceph, etc.).
There are two main ways to create a PV volume.
# kubectl
get pv -o wide
Or
# kubectl describe pv <pv_name>
Detailed
Explanation of Key Fields:-
1. ACCESS MODES
- RWO (ReadWriteOnce) → Can be mounted as read-write
by a single node.
- ROX (ReadOnlyMany) → Can be mounted as read-only
by multiple nodes.
- RWX (ReadWriteMany) → Can be mounted as read-write
by multiple nodes.
2. RECLAIM
POLICY
Determines
what happens to the PV after the PVC using it is deleted.
- Retain → The PV is not deleted and
must be manually cleaned up.
- Recycle → (Deprecated) The PV is
scrubbed and made available again.
- Delete → The PV and its associated
storage are automatically deleted.
3. STATUS
Shows the
current state of the PV:
- Available → The PV is ready to be claimed
by a PVC.
- Bound → The PV is claimed and in use
by a PVC.
- Released → The PVC has been deleted, but
the PV is not yet reusable.
- Failed → The PV encountered an error.
4. storageclass
- Defines the storage
provisioning method.
- If manual, it means the PV was
manually created.
- If using dynamic provisioning
(e.g., AWS EBS, GCE Persistent Disk), it would show a class like gp2 (AWS
EBS default class).
- StorageClass can be defined with any name.
5.VOLUMEATTRIBUTESCLASS
- Used in Container Storage
Interface (CSI) drivers.
- <unset> means it’s not
configured.
- If a CSI driver is used, this
may contain extra volume attributes.
6.VOLUME
MODE: Filesystem
In
Kubernetes, VOLUME MODE determines how a Persistent Volume (PV) is
formatted and used by a pod. The two possible values are:
1. Filesystem (default)
- The volume is formatted with a filesystem (e.g., ext4, xfs) and mounted into a pod as a directory.
- Used for normal file-based access.
- Example: A pod writing logs or storing application data in a directory.
2. Block
- The volume is presented as a raw block device to the container.
- No filesystem is applied, and the application must handle reading/writing directly to the device.
- Used for databases or high-performance applications that need direct disk access.
There are two main ways to create a PV volume.
Types of Persistent Volumes (PV):
Static Provisioning:
- Admin manually creates PVs before they are requested by PVCs.
- Example: Using an NFS server, manually setting up PVs.
- The administrator will first create the PV manually, then tell the developer, and then the developer will add the PVC size to the manifest file.
- Kubernetes automatically provisions PVs when a PVC is created.
- Uses StorageClass to define the type of storage (AWS, Azure, GCE, etc.).
- Example: Cloud-based storage dynamically allocated to PVCs.
- It is the method in which the cluster administrator doesn’t provision the PVs manually beforehand. Rather in this process, whenever a POD requires some storage space, the Kubernetes cluster then and there provision the required PV for that POD and allocate that PV to it.
Note :-
1. In
static, once the PVC is removed from the PV, the PV does not mount any PVC. If
you edit the static PV, then PVC will be mounted again, but it is best to use
dynamic PV.
2. bind PVC
to PV.
The PVC will
be mounted only when all the resources like STORAGECLASS , RECLAIM POLICY
and ACCESS MODES of the PV match
with the PVC. If there is no match then the PVC will go into pending status.
############# PVC ############
2.What is a Persistent Volume Claim (PVC)?
A Persistent Volume Claim (PVC) is a request made by a pod to use a PV. The pod does not directly mount a PV; instead, it claims storage through a PVC.
# kubectl get pvc -o wide
Explanation
of Parameters
Detailed
Explanation of Key Fields
1️.NAME
- This is the name of the PVC.
- In this case, mysql-data-mysql-0
is likely a PVC created by a StatefulSet for a MySQL Pod.
2️.STATUS
Indicates
the current state of the PVC:
- Pending → The PVC is waiting for a
matching PV to be created or bound.
- Bound → The PVC is successfully
linked to a PV.
- Lost → The PV was deleted but the
PVC still exists.
Why is
the PVC in Pending state?
- No available PV matches the
PVC's storageClass, size, or access mode , selector and label
- Dynamic provisioning is not
enabled or failed.
3️.VOLUME
- Displays the name of the PV that
has been bound to the PVC.
4️.CAPACITY
- Shows the allocated storage
from the PV once it's bound.
5️.ACCESS MODES
Defines how
the volume can be accessed:
- RWO (ReadWriteOnce) → Mounted as read/write by a
single node.
- ROX (ReadOnlyMany) → Mounted as read-only by
multiple nodes.
- RWX (ReadWriteMany) → Mounted as read/write by
multiple nodes.
Example:
- If using local storage or hostPath,
you typically see RWO.
- If using NFS or CephFS,
you may see RWX or ROX.
6️.STORAGECLASS
- Defines the storage
provisioning method.
- Here, mysql-storage is
specified, meaning Kubernetes is looking for a PV or dynamic storage with
this class.
- If dynamic provisioning is
enabled, the cluster should automatically create a PV for this PVC.
Troubleshooting
Pending PVC with StorageClass:
- If no PV is available with the
required size and storage class, the PVC remains Pending.
- If using a dynamic storage
class (e.g., AWS EBS, GCE Persistent Disk, NFS), make sure the
provisioner is correctly set up.
7️.VOLUMEATTRIBUTESCLASS
- Used in Container Storage
Interface (CSI) drivers.
- <unset> means it’s not in
use.
- If a CSI driver is managing the
volume, this field may contain extra attributes.
8️.AGE
- Shows how long ago the PVC was
created.
Volume Plugin | ReadWriteOnce | ReadOnlyMany | ReadWriteMany | ReadWriteOncePod |
AWSElasticBlockStore | Yes | No | No | No |
AzureFile | Yes | Yes | Yes | No |
AzureDisk | Yes | No | No | No |
CephFS | Yes | Yes | Yes | No |
Cinder | Yes | No | No | No |
CSI | depends on the driver | depends on the driver | depends on the driver | depends on the driver |
FC | Yes | Yes | No | No |
FlexVolume | Yes | Yes | depends on the driver | No |
Flocker | Yes | No | No | No |
GCEPersistentDisk | Yes | Yes | No | No |
Glusterfs | Yes | Yes | Yes | No |
HostPath | Yes | No | No | No |
iSCSI | Yes | Yes | No | No |
Quobyte | Yes | Yes | Yes | No |
NFS | Yes | Yes | Yes | No |
RBD | Yes | Yes | No | No |
VsphereVolume | Yes | No | - (works when Pods are collocated) | No |
PortworxVolume | Yes | No | Yes | No |
StorageOS | No | No | No | No |
How PVC Binds to a PV.
Once a PVC is created, Kubernetes automatically finds a matching PV (based on storageClassName, accessModes, and capacity).
- If a matching PV is found, it is bound to the PVC.
- If no matching PV exists, the PVC remains in a "Pending" state until a PV is available.
No comments:
Post a Comment