## Kubernetes Storage Overview
Kubernetes abstracts underlying storage with PersistentVolumes (PVs), PersistentVolumeClaims (PVCs), and StorageClasses, crucial for stateful applications.
## PersistentVolumes (PVs)
A PersistentVolume (PV) is a cluster-wide storage resource, provisioned by an administrator or dynamically. It represents actual storage (e.g., NFS, cloud disks) and is independent of Pods. PVs define access modes and a reclaim policy.
## PersistentVolumeClaims (PVCs)
A PersistentVolumeClaim (PVC) is a user's request for storage. Kubernetes binds a PVC to an available PV that matches its requirements (size, access mode). If no suitable PV exists, the PVC remains pending or triggers dynamic provisioning.
## StorageClasses & Dynamic Provisioning
A StorageClass defines a "class" of storage, specifying a provisioner (e.g., `kubernetes.io/aws-ebs`) and parameters. It enables dynamic provisioning: when a PVC requests a StorageClass, the provisioner automatically creates a new PV on the backend storage to fulfill the claim, automating storage setup.
## Access Modes & Reclaim Policy
Access Modes dictate how storage can be mounted:
The Reclaim Policy defines PV behavior after its PVC is deleted:
## Using Storage in Pods
Pods use persistent storage by referencing a PVC in their `volumes` section and then mounting that volume into containers via `volumeMounts`. The Pod interacts with the PVC, which is bound to a PV.
```yaml
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
image: nginx
volumeMounts:
mountPath: /data
volumes:
persistentVolumeClaim:
claimName: my-pvc
```