K8S Storage¶
39 cards ā š¢ 8 easy | š” 12 medium | š“ 8 hard
š¢ Easy (8)¶
1. What is the relationship between a PersistentVolume (PV) and a PersistentVolumeClaim (PVC)?
Show answer
A PV is a cluster-level storage resource. A PVC is a namespace-scoped request for storage. Pods reference PVCs, and Kubernetes binds PVCs to matching PVs based on access mode, storage class, and capacity. The binding is exclusive.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
2. What are the three classic PersistentVolume access modes and what does each allow?
Show answer
ReadWriteOnce (RWO): mounted read-write by a single node. ReadOnlyMany (ROX): mounted read-only by many nodes. ReadWriteMany (RWX): mounted read-write by many nodes. RWO is the most common since block storage is single-attach.Remember: RWO=ReadWriteOnce, ROX=ReadOnlyMany, RWX=ReadWriteMany. O=One, X=Many.
3. What is the purpose of a StorageClass in Kubernetes?
Show answer
A StorageClass defines how storage is provisioned. It names a provisioner (CSI driver), sets provider-specific parameters (disk type, IOPS), configures the reclaim policy, and controls volume binding mode. It enables dynamic provisioning so admins do not need to pre-create PVs.Remember: StorageClass = PV factory. Dynamic provisioning ā no pre-created PVs needed.
Example: `kubectl get sc`. Default SC handles PVCs that omit storageClassName.
4. What are the PersistentVolume reclaim policies and when should you use each?
Show answer
Retain: PV persists after PVC deletion, admin must manually reclaim (use for databases). Delete: PV and underlying storage are deleted when PVC is deleted (use for ephemeral workloads). Recycle is deprecated and should not be used.Remember: Retain(manual), Delete(auto), Recycle(deprecated). Dynamic default=Delete.
Gotcha: RetaināPV becomes Released, not Available. Manual intervention needed.
5. True or False? Kubernetes provides data persistence out of the box, so when you restart a pod, data is saved
Show answer
False. Kubernetes does NOT provide data persistence by default. Container filesystems are ephemeral ā data is lost when a Pod restarts. You need PersistentVolumes (PV/PVC) for durable storage.Under the hood: PV = cluster-scoped storage (EBS, NFS, local). PVC = namespace-scoped request that binds to a matching PV.
Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
6. True or False? A volume defined in Pod can be accessed by all the containers of that Pod
Show answer
True. A volume defined in a Pod spec is accessible to all containers in that Pod. Each container mounts it via volumeMounts, and they can share data through it.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
7. What is a volume in regards to Kubernetes?
Show answer
A directory accessible by the containers inside a certain Pod and containers. The mechanism responsible for creating the directory, managing it, ... mainly depends on the volume type.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
8. What is a Persistent Volume (PV) and Persistent Volume Claim (PVC) in Kubernetes?
Show answer
* Persistent Volume (PV):* Represents a piece of storage in the cluster that has been provisioned by an administrator.
* Can be used to store data independently of any particular pod.
* Provides a way to manage storage resources in a cluster.
* Persistent Volume Claim (PVC):
* Represents a request for storage by a user or pod.
* Binds to a Persistent Volume, making the storage available to the pod.
* Allows for dynamic provisioning of storage resources.
Persistent Volumes and Persistent Volume Claims provide a mechanism for decoupling storage from pod lifecycles.
š” Medium (12)¶
1. Explain the dynamic provisioning flow when a pod requests storage via a PVC.
Show answer
1) Pod references a PVC. 2) PVC references a StorageClass. 3) Kubernetes calls the CSI driver named in the StorageClass. 4) The driver creates the underlying volume. 5) A PV is automatically created and bound to the PVC. 6) The volume is mounted into the pod. WaitForFirstConsumer delays this until a pod is scheduled, ensuring zone alignment.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
2. What is the difference between Immediate and WaitForFirstConsumer volume binding modes?
Show answer
Immediate provisions the volume as soon as the PVC is created. WaitForFirstConsumer delays provisioning until a pod using the PVC is scheduled to a node. WaitForFirstConsumer is critical on cloud providers to ensure the volume is created in the same availability zone as the node.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
3. How does StatefulSet storage work with volumeClaimTemplates?
Show answer
StatefulSets use volumeClaimTemplates to create one PVC per replica, named -Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
4. How do you create and restore a VolumeSnapshot in Kubernetes?
Show answer
Create a VolumeSnapshot referencing a PVC and a VolumeSnapshotClass. To restore, create a new PVC with a dataSource block pointing to the snapshot (kind: VolumeSnapshot). The CSI driver must support snapshots and a VolumeSnapshotClass must exist.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
5. What reclaim policies are there?
Show answer
* Retain* Delete
Note: Recycle was deprecated in K8s 1.22 and removed in 1.24. Use dynamic provisioning instead.
Remember: Retain(manual), Delete(auto), Recycle(deprecated). Dynamic default=Delete.
Gotcha: RetaināPV becomes Released, not Available. Manual intervention needed.
6. Explain "Dynamic Provisioning" and "Static Provisioning"
Show answer
The main difference relies on the moment when you want to configure storage. For instance, if you need to pre-populate data in a volume, you choose static provisioning. Whereas, if you need to create volumes on demand, you go for dynamic provisioning.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
7. Which problems, volumes in Kubernetes solve?
Show answer
1. Sharing files between containers running in the same Pod2. Storage in containers is ephemeral - it usually doesn't last for long. For example, when a container crashes, you lose all on-disk data. Certain volumes allows to manage such situation by persistent volumes
Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
8. Explain Volume Snapshots
Show answer
Volume snapshots let you create a copy of your volume at a specific point in time.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
Remember: Volume Snapshots are the K8s equivalent of cloud disk snapshots. CSI driver must support the Snapshot capability.
Gotcha: Not all storage providers support snapshots. Check `kubectl get volumesnapshotclass` ā empty means no snapshot support.
9. True or False? Kubernetes manages data persistence
Show answer
False. Kubernetes provides the framework (PV, PVC, StorageClass) but does not manage the actual data persistence. Storage backends (cloud disks, NFS, Ceph) handle the physical storage.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
10. Explain ephemeral volume types vs. persistent volumes in regards to Pods
Show answer
Ephemeral volume types have the lifetime of a pod as opposed to persistent volumes which exist beyond the lifetime of a Pod.Remember: PV lifecycle: AvailableāBoundāReleased. Modes: RWO, ROX, RWX.
Remember: O=One, X=Many. RWO=one writer, ROX=many readers, RWX=many writers.
Remember: Ephemeral = pod lifetime (emptyDir, configMap, secret). Persistent = beyond pod lifetime (PVC to PV).
Analogy: Ephemeral volumes are like RAM ā fast, temporary. Persistent volumes are like disk ā slower, durable.
11. Explain "Persistent Volumes". Why do we need it?
Show answer
Persistent Volumes allow us to save data so basically they provide storage that doesn't depend on the pod lifecycle.Remember: PV lifecycle: AvailableāBoundāReleased. Modes: RWO, ROX, RWX.
Remember: O=One, X=Many. RWO=one writer, ROX=many readers, RWX=many writers.
12. What types of persistent volumes are there?
Show answer
* NFS* iSCSI
* CephFS
* ...
Remember: PV lifecycle: AvailableāBoundāReleased. Modes: RWO, ROX, RWX.
Remember: O=One, X=Many. RWO=one writer, ROX=many readers, RWX=many writers.
š“ Hard (8)¶
1. A PVC is stuck in Pending state. Walk through your debugging process.
Show answer
1) kubectl describe pvc to check events. Common causes: no matching PV and no StorageClass provisioner (check SC exists and CSI driver pods are healthy), WaitForFirstConsumer mode (normal until a pod is scheduled), storageclass not found (typo in SC name), exceeded ResourceQuota, or requested capacity exceeds provider limits. 2) Check CSI driver pods in kube-system. 3) Check node availability zones vs volume binding mode.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
2. A pod fails to start with a multi-attach error on an RWO volume. What happened and how do you fix it?
Show answer
An RWO volume is still attached to a previous node, usually because the old node was not properly drained or is in a NotReady state. The volume cannot attach to the new node until it is detached from the old one. Fix: force-detach the volume via the cloud provider API or delete the old VolumeAttachment object. Prevent by using proper node drain procedures and setting appropriate pod disruption budgets.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
3. What is the CSI architecture in Kubernetes and how do you verify a CSI driver is healthy?
Show answer
CSI drivers run as a DaemonSet (node plugin on every node for mount/unmount) and a Deployment (controller for provision/attach/snapshot). Verify health: kubectl get pods -n kube-system -l app=Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
4. How does PVC expansion work and what are the operational risks?
Show answer
PVC expansion requires allowVolumeExpansion: true on the StorageClass. Patch the PVC with a larger storage request. Most CSI drivers support online expansion but some require a pod restart for filesystem resize. Risks: expansion is one-way (cannot shrink), filesystem resize can fail leaving the volume in a resizing condition, and not all storage backends support online expansion. Always snapshot before expanding.Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
5. How does Kubernetes handle storage orchestration, and what are the available storage classes?
Show answer
Storage Orchestration in Kubernetes:* Kubernetes abstracts storage using the StorageClass API.
* Storage classes define the type of storage, provisioning, and reclaim policies.
* Dynamic provisioning allows automatic creation of persistent volumes based on demand.
Remember: StorageClass = PV factory. Dynamic provisioning ā no pre-created PVs needed.
Example: `kubectl get sc`. Default SC handles PVCs that omit storageClassName.
6. How does Kubernetes handle storage orchestration?
Show answer
* Storage Orchestration: Kubernetes abstracts storage through Persistent Volumes (PVs) and Persistent Volume Claims (PVCs).* Administrators provision PVs, and users request storage through PVCs.
* Storage Classes define the characteristics of the underlying storage, allowing dynamic provisioning.
* Kubernetes provides a flexible storage model, allowing applications to request and use storage resources without detailed knowledge of the underlying infrastructure.
Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
7. Provide at least one use-case for each of the following volume types:
Show answer
* EmptyDir: You need a temporary data that you can afford to lose if the Pod is deleted. For example short-lived data required for one-time operations.* hostPath: You need access to paths on the host itself (like data from `/sys` or data generated in `/var/lib`)
Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.
8. What volume types are you familiar with?
Show answer
* emptyDir: created when a Pod assigned to a node and ceases to exist when the Pod is no longer running on that node* hostPath: mounts a path from the host itself. Usually not used due to security risks but has multiple use-cases where it's needed like access to some internal host paths (`/sys`, `/var/lib`, etc.)
Remember: Storage abstraction: StorageClassāPVāPVCāPod mount. Dynamic provisioning automates PV.