Configure volume types, access modes and reclaim policies
5 minutes
5 Questions
In the Certified Kubernetes Administrator (CKA) curriculum, managing storage requires configuring PersistentVolumes (PVs) to ensure data persists and interacts correctly with Pods via PersistentVolumeClaims (PVCs).
**Volume Types**: Kubernetes supports various storage backends defined in the PV ma…In the Certified Kubernetes Administrator (CKA) curriculum, managing storage requires configuring PersistentVolumes (PVs) to ensure data persists and interacts correctly with Pods via PersistentVolumeClaims (PVCs).
**Volume Types**: Kubernetes supports various storage backends defined in the PV manifest. These range from cloud-provider specific block storage (e.g., `awsElasticBlockStore`, `azureDisk`, `gcePersistentDisk`) to network file systems (`nfs`) and local node storage (`hostPath`). The Container Storage Interface (`csi`) is the modern standard for integrating third-party storage drivers. Configuration involves defining the specific plugin fields in the PV `spec` to match the underlying infrastructure.
**Access Modes**: Defined under `spec.accessModes`, these dictate how the volume can be mounted by nodes. `ReadWriteOnce` (RWO) allows the volume to be mounted as read-write by a single node. `ReadOnlyMany` (ROX) allows multiple nodes to mount it read-only. `ReadWriteMany` (RWX) allows multiple nodes to mount it read-write (typically required for NFS). Note that the volume type determines which modes are valid; for instance, standard block storage usually only supports RWO.
**Reclaim Policies**: The `spec.persistentVolumeReclaimPolicy` determines the fate of the PV after the bound PVC is deleted. `Retain` preserves the PV and its data, requiring manual administrative cleanup. `Delete` automatically removes both the PV object and the external storage asset (common in dynamic provisioning). `Recycle` (deprecated) performs a basic data scrub to make the volume available again.
Administrators configure these settings via YAML files. Additionally, `StorageClasses` are used to define these parameters for dynamic provisioning, ensuring new volumes are created with the specific type and reclaim policy automatically.
Mastering Storage: Volume Types, Access Modes, and Reclaim Policies for CKA
Why is this Important? In the CKA exam and real-world Kubernetes, managing state is crucial. While Pods are ephemeral, data often needs to persist. Understanding Volume Types, Access Modes, and Reclaim Policies ensures you can configure storage that survives Pod restarts, creates the correct binding relationships between requests (PVCs) and assets (PVs), and handles data lifecycle correctly.
What are they? 1. Volume Types: These define the actual storage backend. In the exam, you will most likely encounter hostPath (storage on the specific node) or generic definitions for Network File Systems (NFS). 2. Access Modes: Define how a volume can be mounted by nodes. They include: - ReadWriteOnce (RWO): Mounted as read-write by a single node. - ReadOnlyMany (ROX): Mounted read-only by multiple nodes. - ReadWriteMany (RWX): Mounted as read-write by multiple nodes. 3. Reclaim Policies: Define what happens to the PV when the claiming PVC is deleted. - Retain: The PV remains existing but is in a 'Released' state. Data is safe but requires manual cleanup before reuse. - Delete: The PV and underlying storage are deleted immediately. - Recycle: (Deprecated) Performs a basic scrub and makes the PV available again.
How it Works Kubernetes decouples storage using PersistentVolumes (PV) (the resource) and PersistentVolumeClaims (PVC) (the request). A PVC searches for a PV that satisfies its requirements (Capacity, Access Mode, and Storage Class). Once bound, the PV belongs to that claim. The Reclaim Policy dictates the fate of the PV once the user deletes the PVC.
How to Answer Questions on Storage Configuration Storage questions usually follow a specific workflow: 1. Create a PV: You will be asked to create a PV with a specific capacity, access mode, and volume type (usually hostPath). 2. Create a PVC: You must create a claim that matches the PV's capacity and access modes to ensure they bind. 3. Mount to a Pod: Configure a Pod to use the PVC as a volume definition. 4. Update Policies: You might be asked to change the reclaim policy of an existing PV to prevent data loss.
Exam Tips: Answering Questions on Configure volume types, access modes and reclaim policies 1. Use the Documentation: Bookmark the 'Persistent Volumes' page. It has the YAML templates for PVs and PVCs. Copy-paste is faster than writing from scratch. 2. Check Access Modes Carefully: Ensure your PVC Access Mode matches the PV. If a PV is ReadWriteOnce, the PVC must ask for ReadWriteOnce to bind. 3. Capacity Matching: A PVC will bind to a PV with equal or greater capacity. If you create a 1Gi PVC, it can bind to a 10Gi PV if no better match exists. 4. Editing Reclaim Policies: If asked to change a policy from Delete to Retain, use kubectl patch pv <pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}' or simply kubectl edit pv <pv-name>. 5. HostPath Syntax: When defining a hostPath PV, remember the syntax: hostPath: path: /data/location type: Directory (or DirectoryOrCreate). 6. Verify Binding: Always run kubectl get pv,pvc after creating your resources. If the status is not Bound, check the events with kubectl describe pvc <name>.