Persistent Storage for Containers and Kubernetes
A practical guide to persistent storage for containers and Kubernetes, from volumes and claims to stateful workloads and storage design decisions.
Keeping Data Beyond a Container
Keeping Data Beyond a Container
Containers are designed to be replaceable: they may stop, restart, or be recreated from an image. Data written only to a container’s writable layer is tied to that container and can be lost when it is removed. If an application must keep data through container replacement, put it in storage whose lifecycle is separate from the container, or use an external data service.
A makes storage available to a container at a filesystem path or as a block device. The specific storage choice depends on how the data is used:
A Docker named is managed by Docker and can be reused by other containers.
A bind mount exposes a chosen host path directly, which is useful when both the host and container need access to the same files.
Ephemeral storage can suit temporary data, such as a cache that can be rebuilt.
The key distinction is whether the data needs to outlive the container. A rebuildable cache may not need ; important application data usually does. But persistence is not the same as backup: a can protect data from some container and Pod replacements without protecting it from accidental deletion, corruption, or loss of the underlying storage system. Plan backups and restores separately, and test that restores work.
How Kubernetes Supplies Storage
How Kubernetes Supplies Storage
Kubernetes separates a workload’s request for storage from the storage resource that supplies it:
A represents storage available to the cluster.
A requests storage, such as a capacity and access mode.
A describes a storage type and its provisioner. It can allow Kubernetes to create a PV dynamically when a matching PVC is made.
The connection works like this: a workload declares its storage needs in a PVC; a matching PV supplies the requested storage, potentially through dynamic provisioning described by a ; and a Pod refers to the PVC and mounts the storage into a container. This lets the workload request storage without embedding a particular storage vendor’s details in its container image.
Worked example: a 10 GiB claim
The source example is a PVC that requests 10 GiB of filesystem storage and specifies ReadWriteOnce. It relies on a default being configured. In other words, the claim states the requested capacity and mounting mode, while the default class supplies the storage-type and provisioner context needed for dynamic provisioning. If no default is configured, this example’s stated assumption is not met.
An access mode describes how a may be mounted; it is not a complete application-level locking or replication strategy. In particular, ReadWriteOnce means read-write mounting by a single node. It does not necessarily mean only one Pod can use the : multiple Pods on that same node may still use it. The storage provider must support the requested access mode.
Also check the reclaim policy. After a claim is released, Delete can remove a dynamically provisioned PV’s underlying , while Retain leaves it for manual handling. Choose deliberately, especially when the data is valuable; releasing a claim can have consequences for the underlying data.
Choosing a Workload Pattern
Choosing a Workload Pattern
A workload is stateful when it depends on data or identity that must persist across replacements. Databases, message brokers, and services that store user-uploaded files are examples. By contrast, replicas in a typical stateless Deployment are interchangeable in a way that Pods are not.
A is useful when an application needs stable Pod identities, per replica, or ordered deployment and scaling. It can create a separate PVC for each Pod from a claim template. If a Pod is rescheduled, Kubernetes can associate that Pod identity with its existing claim. This association is subject to storage-system availability and scheduling constraints; it is not guaranteed regardless of where the Pod can run.
A Deployment with a PVC may be sufficient for a single instance when stable per-replica identity and ordered operations are not needed. The choice is about the workload’s identity and storage needs, not simply whether it uses a .
Neither a nor alone provides high availability. Persistence can help retain data across some replacements, but the application still needs an appropriate design for replication, failover, and .
Evaluate Storage for the Application
Evaluate Storage for the Application
A storage choice is not just a capacity decision. Evaluate it against how the application handles data, failures, and access:
Durability and : Set backup frequency and retention, define restore procedures and objectives, and test restores. A persistent is not a substitute for a tested backup plan.
Availability and consistency: Ask what happens if a node or the storage system fails. Kubernetes attachment is separate from application-level replication and consistency requirements.
Performance: Estimate capacity, latency, throughput, and I/O patterns. A database may have different needs from logs, media files, or a rebuildable cache.
: Confirm that the provider supports the required access mode. Also determine whether concurrent writers are safe for the application and filesystem; an access mode alone does not provide application-level coordination.
Lifecycle and cost: Consider provisioning, expansion, snapshots, retention, and cleanup. Understand what deleting claims or workloads may mean for storage and data before doing it.
Security: Apply least-privilege access, protect sensitive data, and evaluate the encryption and access controls offered by the storage platform.
These checks connect the earlier choices: select storage that can meet the application’s access and performance needs, decide how its lifecycle and reclaim behavior should work, and plan and security independently of persistence.
: A workload that depends on data or identity that must persist across replacements.