Cheat SheetsKubernetesStorage

Storage — Cheat Sheet

Kubernetes · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Storage
Kubernetes1 topicsQuick revision reference
1

Persistent Storage — PV, PVC & StorageClass

Kubernetes PersistentVolumes (PV) and PersistentVolumeClaims (PVC) decouple storage provisioning from consumption. StorageClasses enable dynamic provisioning of cloud volumes (EBS, GCE PD, Azure Disk).

  • PVC is the request for storage; PV is the actual storage; StorageClass handles dynamic provisioning.
  • ReadWriteOnce (RWO): one node at a time — for databases. ReadWriteMany (RWX): multiple nodes — for shared file storage.
  • reclaimPolicy: Delete destroys the volume when PVC is deleted — use Retain for production databases.
  • StatefulSets give pods stable names (pod-0, pod-1) and each pod its own PVC via volumeClaimTemplates.
  • Deployments = stateless; StatefulSets = stateful (databases, caches with persistence).
  • Dynamic provisioning on cloud means you only create a PVC — K8s creates the EBS/GCE/Azure disk automatically.
pvc.yaml — PersistentVolumeClaim
# pvc.yaml — request 20 GB of SSD storage

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  name: postgres-data

  namespace: production

spec:

  accessModes:

    - ReadWriteOnce          # RWO: mounted read-write by ONE node at a time

    # ReadWriteMany          # RWX: mounted by multiple nodes (NFS, EFS)

    # ReadOnlyMany           # ROX: mounted read-only by multiple nodes

  storageClassName: gp3      # which StorageClass to use (cloud-specific)

  resources:

    requests:

      storage: 20Gi          # request 20 GB



# K8s automatically provisions an AWS EBS gp3 volume and binds it to this PVC



# Use PVC in a Deployment

spec:

  template:

    spec:

      containers:

        - name: postgres

          image: postgres:16-alpine

          volumeMounts:

            - name: data

              mountPath: /var/lib/postgresql/data

      volumes:

        - name: data

          persistentVolumeClaim:

            claimName: postgres-data    # references the PVC above



# Check PVC status

kubectl get pvc

# NAME           STATUS  VOLUME        CAPACITY  ACCESS MODES  STORAGECLASS

# postgres-data  Bound   pvc-abc123    20Gi      RWO           gp3
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/kubernetes