Share persistent volume claims amongst containers in Kubernetes/OpenShift
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Persistent Volume Claims Sharing in Kubernetes/OpenShift
In Kubernetes and OpenShift, persistent storage is fundamental in ensuring that stateful applications and data-heavy workloads can store and retrieve persistent data. Sharing persistent volume claims (PVCs) among containers is a powerful feature that can be used to facilitate certain types of applications and improve data reuse between pods.
Understanding Persistent Volumes (PVs) and Claims (PVCs)
- Persistent Volumes (PVs):
- Description: PVs are storage resources in Kubernetes that are configured by an administrator. These resources are defined in the cluster, much like a node is a cluster resource.
- Lifecycle: Exists independently of the pods; not inside any namespace.
- Persistent Volume Claims (PVCs):
- Description: PVCs are requests for PVs in Kubernetes. Think of a PVC as a specific storage need or user request that dynamically or statically binds to an existing PV.
- Lifecycle: Bounded to a specific namespace.
Sharing PVCs Among Containers
One of the robust features of Kubernetes/OpenShift is the ability to share storage, in the form of PVCs, among multiple pods. Here’s how you can understand and implement this:
- ReadWriteMany (RWX) Access Mode:
- Definition: This access mode allows multiple nodes to read and write to the same storage.
- Use Cases: Ideal for applications that need shared state or configuration, such as a shared cache, logs, or shared libraries.
- Volume Configuration Example: In scenarios where containers need shared access to storage, you will configure PVCs with the
ReadWriteManyaccess mode. Here is an example YAML configuration:- ReadWriteMany
- name: my-container
- mountPath: "/mnt/shared"
- name: shared-storage
- name: another-container
- mountPath: "/mnt/shared"
- name: shared-storage
- Data Consistency: Ensure the application logic handles concurrent reads and writes if necessary.
- Filesystem Type: Some filesystems may support concurrent access better than others; choose based on requirements.
- Performance Implications: Multiple nodes accessing the same volume can introduce performance bottlenecks.
- Access Modes and Storage Class: Ensure the underlying storage class supports
ReadWriteMany.
Related reading
- Share storage/volume between worker nodes in Kubernetes?
- Shared dependencies with HELM
- Should dependencies between Helm charts reflect dependencies between microservices?
- Show metrics in Grafana from the Kubernetes Pod that was scraped last by Prometheus
- Sharing precompiled assets across docker containers
- Should I use AWS Elastic Beanstalk or the Amazon EC2 Container Service ECS to scale Docker containers?
- sidecar vs init container in kubernetes
- Skaffold syncs files but pod doesn't refresh

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.