DEV Community

Anil Kumar
Anil Kumar

Posted on

๐ŸŒŸ Persist your data with PV and PVC ๐ŸŒŸ

Image description

Image description

Image description

Image description

Hello Cloudees โ˜๏ธ!
๐Ÿš€ Mastering Persistent Storage in Kubernetes! โ˜๏ธ
๐Ÿ”น Ever lost important data when a pod restarted?
๐Ÿ”น Want to ensure your applications have reliable storage in K8s?

Letโ€™s break it down! โฌ‡๏ธ
Before getting into the main topic let's understand the terms.

๐Ÿ†š ๐ธ๐‘โ„Ž๐‘’๐‘š๐‘’๐‘Ÿ๐‘Ž๐‘™ ๐‘ฃ๐‘  ๐‘ƒ๐‘’๐‘Ÿ๐‘ ๐‘–๐‘ ๐‘ก๐‘’๐‘›๐‘ก ๐‘†๐‘ก๐‘œ๐‘Ÿ๐‘Ž๐‘”๐‘’:
โœ… ๐‘ฌ๐’‘๐’‰๐’†๐’Ž๐’†๐’“๐’‚๐’ ๐’”๐’•๐’๐’“๐’‚๐’ˆ๐’†: Data is tied to the lifecycle of the pod, when the pod is deleted/restart the data is lost. ๐Ÿ“ Example: emptyDir()
โœ…๐‘ท๐’†๐’“๐’”๐’Š๐’”๐’•๐’†๐’๐’• ๐’”๐’•๐’๐’“๐’‚๐’ˆ๐’†: Data is independent irrespective of the pod lifecycle. It can be reused by other pods. ๐Ÿ“ Example: PVs, cloud storage, NFS

In Persistent storage concept we have "Persistent Volume"
โ“What is Persistent Volume?
โœ… It is a piece of storage that has been provisioned(allocated) and made available to use by the pods.
๐Ÿ“Œ Fixed storage (static/dynamic provisioning)
๐Ÿ“Œ Flexible storage (thin provisioning)

๐ŸŸ ๐‘ณ๐’Š๐’‡๐’†๐‘ช๐’š๐’„๐’๐’† ๐’๐’‡ ๐‘ท๐‘ฝ:
1๏ธโƒฃ ๐˜—๐˜ณ๐˜ฐ๐˜ท๐˜ช๐˜ด๐˜ช๐˜ฐ๐˜ฏ๐˜ช๐˜ฏ๐˜จ: Created manually (admin) or dynamically (StorageClass). Three types of provisioning ( Static, Dynamic, Thin)
2๏ธโƒฃ ๐˜‰๐˜ช๐˜ฏ๐˜ฅ๐˜ช๐˜ฏ๐˜จ: PVs bind to Persistent Volume Claims (PVCs) when storage requirements match.
3๏ธโƒฃ ๐˜œ๐˜ด๐˜ข๐˜จ๐˜ฆ: Pods access storage via PVCs.
4๏ธโƒฃ ๐˜™๐˜ฆ๐˜ค๐˜ญ๐˜ข๐˜ช๐˜ฎ๐˜ช๐˜ฏ๐˜จ: When a PVC is deleted, the PV follows its Reclaim Policy (Retain, Delete, Recycle (deprecated)).

โœ… ๐‘ท๐’“๐’๐’” & โŒ ๐‘ช๐’๐’๐’” ๐’๐’‡ ๐‘ผ๐’”๐’Š๐’๐’ˆ ๐‘ท๐‘ฝ๐’”
โœ… ๐‘ท๐’“๐’๐’”:
โœ”๏ธ Data will be still available even if the pod deleted.
โœ”๏ธ PV's can be backed by various types of storage ( Local Disks, network-attached storage/cloud based storage), providing the flexibility in choosing the right storage solution for our needs.
โŒ ๐‘ช๐’๐’๐’”:
โš ๏ธ Setup & management complexity, especially with different storage backends.
โš ๏ธ Cross-environment PV management requires monitoring & resource management.

๐ŸŽฏ ๐‘ต๐’†๐’™๐’• ๐‘ป๐’๐’‘๐’Š๐’„: Migrating data between Persistent Volumes!
๐Ÿ’ก ๐ป๐‘œ๐‘ค ๐‘Ž๐‘Ÿ๐‘’ ๐‘ฆ๐‘œ๐‘ข ๐‘ข๐‘ ๐‘–๐‘›๐‘” ๐‘ƒ๐‘’๐‘Ÿ๐‘ ๐‘–๐‘ ๐‘ก๐‘’๐‘›๐‘ก ๐‘†๐‘ก๐‘œ๐‘Ÿ๐‘Ž๐‘”๐‘’ ๐‘–๐‘› ๐พ๐‘ข๐‘๐‘’๐‘Ÿ๐‘›๐‘’๐‘ก๐‘’๐‘ ? ๐ท๐‘Ÿ๐‘œ๐‘ ๐‘ฆ๐‘œ๐‘ข๐‘Ÿ ๐‘กโ„Ž๐‘œ๐‘ข๐‘”โ„Ž๐‘ก๐‘  ๐‘–๐‘› ๐‘กโ„Ž๐‘’ ๐‘๐‘œ๐‘š๐‘š๐‘’๐‘›๐‘ก๐‘ ! ๐Ÿ‘‡

Top comments (0)