Explore key concepts of Kubernetes volumes, persistent storage types, and data management strategies within containerized environments. Assess your understanding of dynamic provisioning, persistent volume claims, access modes, and storage configuration best practices.
Which statement best describes the relationship between a Persistent Volume (PV) and a Persistent Volume Claim (PVC) in Kubernetes?
Explanation: A PVC acts as a user's request for storage, specifying size and access requirements, and it binds to a matching PV available in the cluster. A PV is never directly attached to a Pod without a PVC; the PVC provides abstraction and decouples usage from provisioning. While PVCs can trigger dynamic PV creation with certain classes, the PVC itself does not manage the PV lifecycle. PVs are not dependent on the order of PVC creation but are matched based on requirements.
If you need your application's data to survive Pod restarts and rescheduling, which type of storage should you use in Kubernetes?
Explanation: A PersistentVolume mounted via a PVC ensures data persists beyond the lifecycle of individual Pods, making it ideal for stateful applications. An emptyDir volume only lasts as long as the Pod and is deleted if the Pod is removed. Storing data in the container's local filesystem is ephemeral and data is lost on restart. Projected volumes aggregate secrets or config data, not meant for general-purpose persistent storage.
Which Kubernetes resource allows for automatic creation of PersistentVolumes when a matching PersistentVolumeClaim is submitted?
Explanation: A StorageClass defines templates and parameters for dynamic volume provisioning, enabling Kubernetes to create PersistentVolumes automatically when a PVC requests storage. ConfigMaps are used for configuration data, not storage provisioning. ReplicaSet ensures the desired number of Pods are running but does not relate to storage. PodTemplate provides a blueprint for Pods, unrelated to persistent storage.
When you specify the accessMode 'ReadWriteMany' for a PVC, what behavior should you expect?
Explanation: The 'ReadWriteMany' mode enables many Pods to mount the same PersistentVolume with both read and write capabilities, supporting scalability for shared storage. 'ReadWriteOnce' would allow only a single Pod to write. 'ReadOnlyMany' only permits reading from multiple Pods. Kubernetes persistent volumes do not automatically create separate data copies for each Pod; that's a misconception.
What is a potential security risk when using a hostPath volume to mount a directory from the node’s filesystem into your Pod?
Explanation: Using hostPath can expose the node's filesystem to Pods, so a compromised Pod could alter or remove critical files, posing a significant security risk. hostPath does not provide automatic encryption. While certain directory access may require elevated privileges, Pods are not privileged by default when using hostPath. hostPath does not replicate data across nodes; it is tied to the specific node.