Persistent Volume Claims in Kubernetes

Persistent Volume Claims in Kubernetes

A friendly, step-by-step guide to how applications in Kubernetes keep their data safe: what a Persistent Volume Claim is, how storage gets attached, how it is secured and monitored, and how to avoid the mistakes that cause data loss.

Imagine you run a small online shop, and its database lives inside a Kubernetes cluster, which is a group of computers managed together as if they were one. One night the computer running the database has a problem. Kubernetes does exactly what it is designed to do: it quietly starts a fresh copy of the database on a healthy computer. The shop is back in a minute. But when you look inside the new database, every order from the past three years is gone.

How can this happen? Because the containers that Kubernetes runs are, by default, forgetful. Everything they write inside themselves disappears when they stop. That is wonderful for a small stateless web page, and a disaster for a database.

The cure is a piece of Kubernetes called the Persistent Volume Claim, usually shortened to PVC. In this guide we will build the idea from zero, one small step at a time. Every new word is explained the first time it appears, and every big idea comes with an everyday comparison so it sticks.

1What Is a Persistent Volume Claim?

To understand a PVC we first need six simple words: container, pod, volume, persistent volume, claim and storage class. Let us meet them one by one.

Word 1

Container and pod

A container is a small, sealed box holding an application and everything it needs to run. A pod is the smallest thing Kubernetes runs, and it holds one or more containers. Pods are temporary: they can be stopped, moved and replaced at any moment.

Word 2

Volume

A volume is a folder that a pod can read and write. Some volumes live and die with the pod. Others are backed by real disks that outlive it.

Word 3

Persistent Volume (PV)

A PV is an actual piece of storage inside the cluster, such as a cloud disk or a network folder. It exists on its own, and it is not tied to any one pod.

Word 4

Persistent Volume Claim (PVC)

A PVC is a request for storage. It says: “I need 20 gigabytes, and I need to be able to read and write it.” Kubernetes finds or creates a matching PV and connects the two.

Word 5

StorageClass

A StorageClass describes a type of storage on offer, such as “fast solid-state disks” or “cheap slow disks”. It also tells Kubernetes how to create that storage on demand.

Word 6

Claim

To “claim” simply means to ask for something and reserve it. A PVC claims storage the way a guest claims a hotel room.

So what exactly is a PVC?

A Persistent Volume Claim is a Kubernetes object in which an application, or the person running it, asks for a certain amount and type of durable storage. A pod then mentions the claim by name and receives a folder that is backed by that storage. If the pod dies and a new one takes its place, the new pod can mention the same claim and see all the old files.

The clever part is the separation of jobs. The person writing the application only says what they need: how much space, how it will be accessed. They do not need to know whether the disk is an Amazon EBS volume, a Google persistent disk or a shelf in the company’s own data centre. Someone else, usually the platform team, decides what kinds of storage exist. The claim is the meeting point between the two.

Everyday analogy

Think of a hotel. The rooms are the Persistent Volumes: real spaces that exist whether or not anyone is staying in them. A booking request that says “one quiet room with a sea view for two nights” is the Persistent Volume Claim. The front desk matches the request to a room, or has a new room prepared. The guest, who is the pod, walks in and uses it. If the guest changes their travel plans, the room, and anything stored in its safe, is still there for the next booking under the same name.

A short history

Kubernetes was released as open source by Google in 2014. The earliest storage support was tied closely to specific vendors: the Kubernetes code itself contained special code for each cloud disk. Persistent volumes and claims arrived in the early years to give applications one common way to ask for storage. Later, dynamic provisioning let the cluster create disks automatically on request, and the Container Storage Interface (CSI) moved vendor-specific code out of Kubernetes into separate plug-in drivers. Today CSI drivers are the normal way to connect storage.

i
Remember this

The PV is the storage, the PVC is the request for storage, and the StorageClass is the menu of storage kinds. Three words, three jobs. Most confusion in this topic comes from mixing them up.

2The Problem PVCs Solve

Kubernetes already gives pods some ways to store files. To see why PVCs were invented, we need to see why those ways are not enough for important data.

Why containers forget

A container starts from a fixed template called an image. Anything the application writes while running goes into a thin, temporary layer on top of that image. When the container stops, that layer is thrown away and the next container starts clean from the template again. This design makes containers easy to copy, replace and scale, which is exactly why Kubernetes loves them.

The same design means that database files, uploaded photos, message queues and search indexes cannot simply be written inside the container. They need a home that survives the container.

The simple options and their limits

emptyDir is a scratch folder created when a pod starts and deleted when the pod leaves its computer. It is perfect for temporary work files and for sharing files between containers in one pod. It is useless for data you want to keep.

hostPath connects a pod to a folder on the computer it happens to run on. The data survives a pod restart, but only if the new pod lands on the very same computer. If Kubernetes moves the pod elsewhere, the data stays behind. It also lets a pod touch the computer’s own files, which is a security risk. Treat it as a tool for special system programs, not for everyday applications.

Persistent volumes with claims separate the life of the data from the life of the pod and from the life of any particular computer. The data lives on independent storage, and Kubernetes reconnects it wherever the pod is placed next.

MethodHow long data livesGood forWeakness
Container’s own layerUntil the container stopsNothing you want to keepEverything is lost on restart
emptyDirUntil the pod leaves its computerScratch space, sharing files between containersDeleted with the pod
hostPathAs long as the computer keeps the folderSpecial system agentsTied to one computer, a security risk
PV with PVCUntil you decide to delete itDatabases, uploads, queues, indexesNeeds a storage system and some planning
flowchart TB
  subgraph WITHOUT["Without a PVC: data dies with the pod"]
    direction LR
    A1["Database Pod v1"] --> D1["Container layer with data"]
    A1 -. "pod fails and is replaced" .-> A2["Database Pod v2"]
    A2 --> D2["Fresh empty layer"]
  end
  subgraph WITH["With a PVC: data outlives the pod"]
    direction LR
    B1["Database Pod v1"] --> C1["PVC named db-data"]
    B2["Database Pod v2"] --> C1
    C1 --> PV1["Persistent Volume on a real disk"]
  end
    
Figure 1. A replacement pod finds an empty layer without a PVC, and finds all the old files with one.
Everyday analogy

Writing important data inside a container is like writing your notes on a whiteboard in a meeting room that is wiped after every meeting. A PVC is like a personal locker in the office building. Meeting rooms change every day, but your locker, with your name on it, stays exactly where it is.

3
objects work together: PV, PVC and StorageClass
0
data survives in a container’s own layer after a restart
1
simple claim replaces vendor-specific storage details in your app
!
Watch out

A demo that works perfectly on a laptop can hide this problem. The data seems fine until the first real restart on a real cluster. Always test what happens to your data when a pod is deleted, before you go live.

3Core Concepts

Storage has more settings than most beginners expect. Learn these eight ideas and every storage conversation in Kubernetes will make sense.

Storage

Persistent Volume

The real storage object. It records the size, the type, the access rules and the location of the actual disk. It belongs to the whole cluster, not to any one team’s namespace.

Request

Persistent Volume Claim

The request, written by the application owner. It lives inside a namespace, which is a private workspace within the cluster, and only pods in that same namespace can use it.

Menu

StorageClass

A named type of storage with a driver, settings and rules. Examples are “fast-ssd” or “cheap-archive”. If a claim names no class, the cluster’s default class, if one is set, is used.

Rules

Access modes

They say who may use the volume at the same time. We explain them in detail below, because choosing the wrong one is a very common source of trouble.

Shape

Volume mode

Filesystem mode gives the pod an ordinary folder. Block mode gives the pod a raw, unformatted disk, which some databases prefer for extra speed.

Cleanup

Reclaim policy

What happens to the storage after the claim is deleted. “Delete” destroys the disk. “Retain” keeps it for a human to handle.

Timing

Binding mode

Decides when a claim is connected to storage: immediately, or only after a pod that needs it has been placed on a computer. The second choice avoids nasty location surprises.

Growth

Volume expansion

A setting on the class that lets you enlarge a claim later. You can make a volume bigger, but you cannot shrink it.

Everyday analogy

Picture a car rental office. The StorageClass is the catalogue: economy, family, luxury. The PVC is your reservation: “a family car for a week”. The PV is the actual car that gets handed over. The access mode is the rule “only one driver at a time”. The reclaim policy is what the company does with the car when you return it: clean it and rent it out again, or send it to the scrapyard.

Understanding access modes

An access mode answers one question: how many computers or pods may use this volume at once, and may they write to it? There are four modes.

Access modeShort nameMeaningTypical example
ReadWriteOnceRWORead and write, but from one computer at a timeA block disk such as Amazon EBS for a database
ReadOnlyManyROXMany computers may read, none may writeShared reference data
ReadWriteManyRWXMany computers may read and write togetherA shared file system such as Amazon EFS or NFS
ReadWriteOncePodRWOPRead and write, but from exactly one podStrict single-writer protection

Notice that ReadWriteOnce is about computers, not pods. Two pods on the same computer can share an RWO volume. If a second pod lands on a different computer, it cannot attach the disk while the first one still holds it. When you see a “multi-attach” error, this rule is almost always the reason.

Also remember that the access mode is a promise about what the storage supports, not a guarantee that Kubernetes will police every write. Choose the mode the underlying storage truly supports, or the claim will stay stuck waiting.

i
Good to know

PVs are shared by the whole cluster, but a PVC belongs to one namespace. Two teams in different namespaces can each have a claim named “data” without any clash, because the claims are private to their own workspaces.

4Architecture and Components

Storage in Kubernetes is a team effort. Several small programs each do one job, and together they turn a short request into a working disk inside a pod.

flowchart LR
  DEV["Developer applies a PVC and a Pod"] --> API["Kubernetes API Server"]
  PVCC["PV Controller"] -->|"watches claims and volumes"| API
  PROV["CSI External Provisioner"] -->|"watches new claims"| API
  PROV --> DRVC["CSI Driver Controller Service"]
  DRVC --> STORE["Storage System such as a cloud disk service"]
  SCHED["Scheduler"] -->|"places the pod on a node"| API
  KUB["Kubelet on the chosen node"] -->|"asks to mount"| DRVN["CSI Driver Node Service"]
  DRVN --> STORE
  KUB --> POD["Pod with the folder mounted"]
    
Figure 2. The main players in storage provisioning and mounting.

Piece by piece

The API server is the cluster’s central notice board. Your claim, the volumes, the storage classes and the pods are all stored there. Every other component watches this board and reacts when something changes.

The PV controller is part of the built-in controller manager. Its job is matchmaking. It looks at every unbound claim and every available volume and connects a claim to a volume that satisfies its size, access mode and class. It also handles what happens when a claim is deleted, following the reclaim policy.

The CSI driver is the plug-in that knows how to talk to one particular storage system. There is a driver for Amazon EBS, another for Amazon EFS, one for Google persistent disks, one for Azure disks, and drivers for on-premises systems such as Ceph. The driver has two halves. The controller half creates, deletes, attaches and resizes volumes. The node half runs on every computer and formats and mounts volumes for pods.

The external provisioner is a helper container that runs alongside the driver. It watches for new claims that need dynamic storage and calls the driver to create the disk, then creates the matching PV object on the driver’s behalf. Similar helpers exist for attaching, resizing and taking snapshots.

The scheduler decides which computer a pod should run on. For storage it is careful: it prefers computers where the pod’s volume can actually be reached, such as the correct availability zone.

The kubelet is the agent on each computer. Once a pod is placed, the kubelet asks the driver’s node half to make the volume appear at a folder path and then hands that folder to the containers.

Everyday analogy

Think of a restaurant. The API server is the order board on the wall. The PV controller is the manager who matches tables to bookings. The provisioner is the purchasing assistant who orders fresh ingredients when the pantry is empty. The CSI driver is the delivery company that knows how to reach each supplier. The kubelet is the waiter who finally brings the plate to your table.

2
halves in a CSI driver: a controller half and a node half
1
driver per storage system, installed once per cluster
Many
helper containers cooperate: provision, attach, resize, snapshot
!
Common surprise

A StorageClass only names a driver. If the driver is not installed, claims that use the class will wait forever with no obvious error. On Amazon EKS, for example, the EBS storage driver is an add-on that you must install and give permissions to.

5How Binding and Provisioning Work Internally

Here is what really happens between the moment you save a claim and the moment it says “Bound”.

The matching loop

Kubernetes controllers follow a habit called the control loop. They compare the world as you asked for it with the world as it is, and they take small steps to close the gap, again and again. The PV controller applies this habit to storage. Whenever a claim appears, changes or is deleted, it wakes up and works out what to do.

flowchart TD
  A["New PVC is created"] --> B{"Does a suitable PV already exist?"}
  B -->|"Yes"| C["PV controller binds the claim to that volume"]
  B -->|"No"| D{"Does the PVC name a usable StorageClass?"}
  D -->|"Yes"| E["Provisioner asks the driver to create a new disk"]
  E --> F["A new PV object is created and bound"]
  D -->|"No"| G["PVC stays Pending until a match appears"]
  C --> H["PVC status becomes Bound"]
  F --> H
    
Figure 3. The decision path from a new claim to a bound volume.
1

Look for an existing match

The controller searches the available volumes for one that is big enough, offers the requested access mode, and belongs to the same class. Among several candidates it picks the smallest that fits, so large volumes are not wasted on small requests.

2

Provision if none exists

If a StorageClass is named and a provisioner is available, the cluster creates a brand-new disk of the requested size. This is called dynamic provisioning.

3

Bind in both directions

The claim records the name of its volume, and the volume records the identity of its claim. This two-way link reserves the volume for that claim alone. A bound volume can never be given to a second claim.

4

Wait for a pod, if asked

With the “wait for first consumer” binding mode, all of the above pauses until a pod that uses the claim has been placed on a computer. The scheduler decides where the pod goes, and only then is the disk created in the right place.

5

Attach and mount

When the pod is ready to start, the driver attaches the disk to the chosen computer, formats it if it is new, and mounts it at a folder the containers can see.

Why “wait for first consumer” matters

Many cloud disks live in exactly one availability zone, which is a separate data centre within a region. An Amazon EBS disk created in one zone cannot be attached to a computer in another. If the disk is created immediately, before any pod is placed, it might be born in a zone where the pod can never run, and the pod would be stuck waiting forever.

Delaying creation until the scheduler has chosen a computer solves this. The disk is then created in the same zone as the pod. For zone-bound storage this is nearly always the correct setting.

Everyday analogy

Imagine ordering a sofa before you know which room of which house it will go in. It might not fit through the door of the flat you finally choose. Waiting to order until you know the destination costs a few days but avoids returning the sofa. Delayed binding is the same sensible patience.

Static provisioning: the manual way

Before dynamic provisioning existed, an administrator created disks by hand and then wrote a PV object for each one. Claims were matched to these ready-made volumes. This still has uses: for example, when you must attach an existing disk that already contains valuable data, or when compliance rules require that a human approves every disk. The price is more manual work and the risk of running out of pre-made volumes.

i
Tip

If a claim stays “Pending”, read its events. They usually say exactly what is missing: no class, no driver, no capacity, or a zone that cannot be satisfied.

6Data Flow and Lifecycle

Now let us follow one claim through its whole life: from the first request, through daily use, to its final deletion.

From request to running pod

sequenceDiagram
  participant U as Developer
  participant A as API Server
  participant S as Scheduler
  participant P as Provisioner
  participant C as CSI Driver
  participant K as Kubelet
  participant D as Cloud Disk
  U->>A: Create the PVC and the Pod
  S->>A: Place the pod on a node
  A->>P: New claim needs storage
  P->>C: Create a volume of the requested size
  C->>D: Allocate the disk
  P->>A: Create the PV and bind it to the claim
  K->>C: Attach and mount the volume
  C->>D: Connect the disk to the node
  K-->>A: Report the pod running with its folder mounted
    
Figure 4. The order of events when a pod needs new storage.

The life of a claim

Claim phase

Pending

The request is saved but not yet matched. It may be waiting for a disk to be created or for a pod to be placed.

Claim phase

Bound

The claim is connected to a volume and ready to be used by pods. This is the healthy, normal state.

Claim phase

Lost

The claim was bound, but its volume has vanished, for example because someone deleted it by hand. This needs urgent attention.

Volume phase

Available

A free volume, not yet claimed by anyone.

Volume phase

Bound

Reserved for a specific claim.

Volume phase

Released

Its claim was deleted, but the data is still there and the volume is not yet cleaned or reused.

Volume phase

Failed

Automatic cleanup or reclaiming did not work, so a human must step in.

Life after the pod: what happens to the data

Deleting a pod never deletes its claim. That is the whole point. The new pod simply names the same claim and finds the same files. Even if you scale a workload down to zero pods for a weekend, the claim and its data stay put.

Deleting the claim is different, and this is where the reclaim policy matters. With the Delete policy, removing the claim also removes the volume and, usually, the real disk with all its data. Dynamically created volumes use this policy by default, because it keeps clusters tidy and costs low. With the Retain policy, the volume moves to the “Released” phase and the disk is kept. An administrator can then copy the data out, or clean the volume and make it available again.

Kubernetes also protects you from one common accident. If a pod is still using a claim, deleting the claim does not take effect right away. It waits until no pod uses it. This safeguard is called storage object in use protection.

Everyday analogy

Returning a hotel room key is like deleting the claim. A “Delete” hotel would clear the room and burn the guest’s belongings. A “Retain” hotel puts the belongings in a box marked “released” and waits for the owner or a manager to decide what to do. Both are valid, but you should know which hotel you booked.

!
Read this twice

For important data such as production databases, set the reclaim policy to Retain, or make sure backups exist. One mistyped command that deletes a claim under the Delete policy can destroy the disk in seconds.

7Usage Patterns You Will Meet

Most real-world storage setups are built from a small set of patterns. Learn to recognise them and you can read almost any configuration.

Dynamic provisioning through a StorageClass

The everyday choice. The application owner writes a claim that names a class, and the cluster creates a matching disk on the spot. Nobody has to prepare storage in advance, so teams move quickly. Most modern clusters have at least one class set as the default, so even a claim that names no class gets storage.

StatefulSets with claim templates

A StatefulSet runs applications that need stable identities, such as database clusters. Its “volume claim template” creates a separate claim for every replica. Replica zero gets its own disk, replica one gets another, and so on. If replica one is restarted, it comes back with the very same disk. This is how systems like PostgreSQL clusters, Kafka and Elasticsearch typically keep their data in Kubernetes.

A shared folder for many pods

When many pods must read and write the same files, such as a website’s uploaded pictures, you need a ReadWriteMany volume backed by a shared file system, for example Amazon EFS or an NFS server. All pods, on any computer, see the same folder.

Expanding a volume

If the storage class allows expansion, you can edit the claim and ask for a larger size. The driver grows the disk, and the file system inside it is grown too, often while the pod keeps running. You can only make a volume bigger, never smaller, so plan a comfortable margin, and remember that cloud providers may limit how often a disk can be resized.

Snapshots and clones

A snapshot is a point-in-time copy of a volume, like a photograph of the folder at one moment. You can create a new claim from a snapshot to restore data or to give a test team a copy of production. A clone creates a new volume directly from an existing claim. Both need a driver that supports them.

Pre-populated volumes

A claim can be created from an existing source, so that a new pod starts with data already in place, such as a trained model or a database seed. This saves time compared with copying files after the pod starts.

Everyday analogy

A StatefulSet with claim templates is like a school giving every student a personal locker with their name on it. A shared RWX volume is like the staff room fridge that everyone uses. A snapshot is a photograph of the locker’s contents taken on a Friday afternoon, in case someone messes it up over the weekend.

How a pod actually uses a claim

The pod does not talk to the disk directly. It lists the claim by name in its volume section and then tells each container which folder path to mount it at. From the application’s point of view, it is simply writing files to an ordinary folder, for example the folder where a database keeps its data. All the complexity of attaching disks, formatting and mounting is hidden below that folder.

Two details often surprise beginners. First, a new, empty disk usually starts with a lost-and-found folder inside it, which some databases refuse to accept as an empty data directory. Pointing the application at a sub-folder solves it. Second, file ownership matters: the application may run as a non-administrator user, so the volume must be writable by that user. Kubernetes lets you set a group ID for the volume in the pod’s security settings so that files become writable.

!
Watch out

Deleting a StatefulSet does not delete its claims by default. Left-behind claims keep their disks, and their cost. Newer Kubernetes versions offer a setting for whether claims are kept or removed when a StatefulSet is deleted or scaled down, so check what your version does.

How big should a claim be?

Sizing is part science and part habit. Start by measuring how much data the application holds today, then estimate how fast it grows each week. Add room for the busiest season, for temporary files the application creates while it works, and for the safety margin that keeps the disk below about 80 percent full. A database also needs extra space for its logs and for maintenance jobs that rewrite tables.

Beginners often make one of two mistakes. Some order a huge disk “just in case”, and pay for empty space every month. Others order the bare minimum and face an emergency when it fills up. Because volumes can be enlarged later, starting modestly and watching the trend is usually the wiser path, as long as expansion is enabled and has been practised.

Remember, too, that size can affect speed. Some disk types give more operations per second to bigger disks, while newer types let you choose speed separately. Read the rules of the disk type you use, so you do not enlarge a disk to gain speed that the type never offered.

Everyday analogy

Choosing a claim size is like choosing a suitcase. Too small and you must sit on the lid to close it. Too large and you pay extra baggage fees for empty space. The best choice fits your things with a little room to spare, and it helps if you can buy an expandable bag.

8Security of Persistent Storage

Persistent storage holds the most valuable thing your company owns: its data. Losing it is bad. Leaking it is worse. Let us look at the layers of protection.

Who

Control who can ask

Use role-based access control to decide who may create, edit or delete claims, volumes and storage classes. Developers usually need claims in their own namespace and nothing more. Volumes and classes should belong to the platform team.

How much

Set quotas

A resource quota caps the total storage and the number of claims one namespace may request. A limit range sets the smallest and largest size of a single claim. Together they stop one team from accidentally ordering hundreds of terabytes.

At rest

Encrypt stored data

Ask the storage system to encrypt disks with a key, for example through AWS Key Management Service. Enable it in the StorageClass so every new disk is protected automatically, without relying on developers to remember.

In transit

Encrypt the network path

Network file systems carry data across the network. Turn on encryption in transit, such as TLS for Amazon EFS, so nobody on the network can read the traffic.

Inside

Run with low privileges

Run application containers as a non-administrator user and set the volume group ID so that only that user can write. Avoid hostPath volumes, because they give a pod direct access to the computer’s own files.

Copies

Protect snapshots and backups

A snapshot contains the same secrets as the disk. Restrict who can read, copy or share snapshots, and encrypt them with the same care as the original data.

Everyday analogy

Protecting storage is like protecting a bank’s vault. There is a guest list for who may enter (access control), a limit on how much anyone may deposit (quotas), a locked box inside the vault (encryption), and a rule that photocopies of the contents get the same guards as the originals (protected snapshots).

Namespaces and isolation

A claim belongs to a single namespace, and a pod can only use claims from its own namespace. This is a helpful boundary between teams. Volumes, however, belong to the whole cluster. If the reclaim policy is Retain and a volume is later reused without being wiped properly, the next claim could see the previous owner’s data. Always clean or delete released volumes with care, and prefer dynamic provisioning, where the storage system starts each new disk fresh.

The driver’s own permissions

The CSI driver creates and deletes real disks, so it holds powerful cloud permissions. On Amazon EKS, give it a dedicated role using the platform’s identity features for service accounts or pod identity, and grant only the actions it needs. Do not attach broad administrator permissions to the computers themselves. If an attacker compromises a driver with wide rights, they can read, copy or destroy every disk in the account.

A short security checklist

Encryption switched on in every StorageClass. Quotas in every namespace. Retain policy or tested backups for critical data. Restricted permissions for the driver. No hostPath in application pods. Regular restore tests, because a backup nobody has ever restored is only a hope, not a plan.

!
Compliance note

Disks live in a particular region and zone. Rules about where personal data may be stored apply to disks and snapshots too. Check where copies are created before you enable cross-region backups.

9Choosing the Right Storage

A PVC is only a request. What answers it decides the speed, cost and behaviour of your data. Choosing well is one of the most important design decisions you will make.

Storage typeExamplesTypical accessNotable traits
Block diskAmazon EBS, Google Persistent Disk, Azure DiskRWOFast, good for databases, usually locked to one zone
Shared file systemAmazon EFS, Google Filestore, Azure Files, NFSRWXMany pods share files, higher latency than block disks
High-performance file systemAmazon FSx familyRWXMade for heavy analytics and machine learning workloads
Local diskLocal volumes on the computer’s own drivesRWOVery fast, but tied to that computer
Software-defined storageCeph with Rook, Longhorn, OpenEBSRWO or RWXRuns on your own servers, needs skilled operators

The AWS way

On Amazon EKS, most teams use the EBS CSI driver for databases and other single-writer workloads, and the EFS CSI driver when many pods need a shared folder. The older built-in cloud storage code has been replaced by CSI drivers, so new clusters should be built on the drivers from the start.

For EBS, the modern general-purpose disk type is gp3. It gives a baseline of 3,000 operations per second and 125 megabytes per second regardless of size, and lets you raise the speed independently of the size. That is usually cheaper and more predictable than the older gp2 type, where speed was tied to size. For heavy databases, the io2 family offers guaranteed high speed at a higher price.

Remember that an EBS disk lives in one availability zone. Use the “wait for first consumer” binding mode so that the disk is created in the same zone as the pod. If that zone is lost, you need a snapshot or replica in another zone to recover. EFS is different: it spreads data across several zones, so pods in any zone can share it, at the price of slightly higher latency.

Everyday analogy

A block disk is like a personal notebook: quick to write in and belongs to one person at a time. A shared file system is like a whiteboard in the team room: everyone can read and write, but it is a little slower because people must take turns and stay in sync. A local disk is a notebook kept in your own pocket: fastest of all, but lost if you lose your coat.

Speed: three numbers to know

IOPS

Operations per second

How many small reads and writes a disk can do each second. Databases that touch many tiny pieces of data care most about this.

Throughput

Megabytes per second

How much data can flow per second. Large file copies, backups and analytics care most about this.

Latency

Delay per operation

How long one request waits for its answer. Low latency makes applications feel snappy and transactions finish quickly.

How to decide

Question 1

Who writes?

One writer at a time points to a block disk. Many writers at once point to a shared file system.

Question 2

How fast must it be?

Measure your database’s real needs. Do not pay for the fastest tier if a mid-range one is enough.

Question 3

What survives a failure?

Decide whether you must survive losing a computer, a zone or a whole region, and choose replication and backups to match.

Question 4

Who runs it?

Managed cloud storage means less work and predictable behaviour. Self-run storage means more control and more on-call duties.

i
Tip

Give your cluster a small, sensible menu of StorageClasses with clear names such as fast, standard and shared. Developers then choose by purpose instead of guessing technical parameters.

10Advantages, Disadvantages and Trade-offs

No tool is perfect. A good engineer knows both what PVCs give and what they cost.

Advantages

  • Data survives pod restarts, upgrades and rescheduling
  • Developers ask for storage without knowing vendor details
  • Dynamic provisioning creates disks on demand with no tickets
  • The same claim works on different clouds with different classes
  • Expansion, snapshots and clones are built in with supporting drivers
  • Claims live in version control like the rest of the application

Disadvantages

  • Zone-bound disks can leave a pod stuck if its zone is unavailable
  • Block disks usually allow only one computer at a time
  • Volumes can be enlarged but never shrunk
  • The Delete policy can destroy data with one mistaken command
  • Forgotten claims and disks keep costing money
  • Storage failures are harder to debug than stateless failures

The trade-offs behind the lists

Block versus shared file. Block disks are fast and simple but serve one computer. Shared file systems serve many but add latency and cost. Choose by how the application really reads and writes, not by habit.

Safety versus tidiness. The Delete policy keeps the cluster clean and the bill low, but one accident can wipe out production data. Retain is safer, but unused disks pile up until someone cleans them. Many companies use Delete for test systems and Retain, plus backups, for production.

Storage in the cluster versus outside it. Running a database inside Kubernetes with PVCs gives portability and one way of working. Using a managed database service outside the cluster, such as Amazon RDS, hands backups, failover and patching to the provider. Neither is always right. Small teams often prefer the managed service, while teams with strong operations skills may prefer control.

Local versus network storage. Local disks give excellent speed but disappear if the computer dies, so the application itself must replicate data across computers. Network disks survive the loss of a computer but add a small delay to every operation.

Pods may come and go, but the data must stay.

11Monitoring, Logging and Metrics

A full disk fails quietly and then suddenly. Good monitoring gives you days of warning instead of a midnight emergency.

Space

Used capacity

The share of each volume that is filled. The kubelet reports this for every mounted claim, and tools such as Prometheus can collect it. Alert well before the disk is full.

Files

Inodes

An inode is a record the file system keeps for each file. A volume with millions of tiny files can run out of inodes while still showing free space. Watch both.

Speed

Disk latency and IOPS

Rising delay means the disk, or the network path to it, is struggling. Compare it with the limits of the disk type you bought.

Requests

Pending claims

A claim that stays Pending for many minutes means something is wrong with the class, the driver or the zone.

Safety

Backup and snapshot success

Track whether each scheduled snapshot finished, how old the newest one is, and whether the last restore test worked.

Money

Cost and orphans

List volumes and claims that no pod has used for weeks. They are often forgotten and still billed every month.

80%
a common warning level for used capacity
90%
a common critical level that should page someone
Days
predict when a disk fills up, not just whether it is full now

Logs and events

When storage misbehaves, the first clues are in the events attached to the claim and the pod. They tell you that provisioning failed, that a volume is waiting to attach, or that a mount timed out. Next look at the logs of the CSI driver and its helper containers, which record every call made to the cloud. Cloud audit logs show who created, changed or deleted a disk, which is invaluable after an accident.

Everyday analogy

Watching disk usage is like watching the fuel gauge on a long drive. You do not want to discover the tank is empty in the middle of a desert. A good alert is the warning light that comes on while there is still enough fuel to reach the next station.

Failure scenarios worth rehearsing

A computer dies while holding a disk

A replacement pod on another computer must wait until the old attachment is released. This can take several minutes, and the pod may show a multi-attach or timeout message. Knowing this is normal saves panic. Applications with strict uptime needs should replicate data across pods instead of relying on one disk.

The disk fills up

Databases may crash or switch to read-only mode. The fix is to expand the claim, clean up old data, or both. Practise expansion beforehand so it is a routine step, not a first-time experiment during an outage.

An entire zone is lost

Zone-bound disks in that zone become unreachable. Recovery means restoring from snapshots into a healthy zone, or promoting a replica that already lives there. Test this path at least once a year.

Someone deletes the wrong claim

With the Delete policy the disk may vanish with it. Recovery depends on backups or snapshots. Open-source tools such as Velero can back up both the cluster objects and the volume data on a schedule.

i
Alert on symptoms

Alert on things that need action: capacity approaching full, a claim stuck in Pending, a failed backup, or a disk running near its speed limit. Skip noisy alerts that nobody can act on at night.

12Design Patterns and Anti-patterns

A pattern is a proven way of solving a common problem. An anti-pattern is a habit that looks sensible at first and causes pain later.

Patterns that work

Pattern

Storage classes by purpose

Offer a small menu named for its purpose, such as fast, standard and shared. Developers pick a purpose, and the platform team controls the technical details.

Pattern

Replicate at the application level

Run a database with several replicas, each with its own volume, so that losing one disk or computer does not lose the data. Storage protects a single copy, replication protects against its loss.

Pattern

Scheduled snapshots with restore drills

Take snapshots on a schedule, keep them for a sensible period, and regularly restore one into a test namespace to prove it works.

Pattern

Separate scratch from data

Put temporary files on emptyDir and only the data that must survive on a claim. This keeps disks smaller, cheaper and easier to back up.

Pattern

Spread across zones

Place replicas in different availability zones, each with a zone-local disk, so that one data-centre failure never takes every copy.

Pattern

Retain for the crown jewels

Use the Retain policy, backed by snapshots, for irreplaceable production data, and the Delete policy for disposable test environments.

Anti-patterns to avoid

ANTI-PATTERN 01 · One disk, no backups Avoid
The habit

Running a production database on a single claim and assuming that “persistent” means “safe”.

What goes wrong

Persistent only means the data outlives the pod. It does not protect against a deleted claim, a corrupted file system, a bad software update, or a lost zone. One mistake and years of data are gone.

Better approach

Combine replication, scheduled snapshots or backups stored elsewhere, the Retain policy, and regular restore tests.

ANTI-PATTERN 02 · hostPath for application data Avoid
The habit

Pointing a pod at a folder on the computer because it is quick and “just works” in testing.

What goes wrong

When the pod moves to another computer, the data seems to vanish. The pod also gains access to the computer’s own files, which is a serious security risk.

Better approach

Use a claim backed by a proper storage class. Reserve hostPath for special system agents that truly need the computer’s files.

ANTI-PATTERN 03 · Never looking at the reclaim policy Avoid
The habit

Accepting whatever default the storage class gives and never checking what deletion will do.

What goes wrong

Someone cleans up a test namespace, deletes a claim, and the real production disk it pointed to disappears. Or the opposite: nobody ever deletes anything and forgotten disks quietly grow the bill.

Better approach

Set the policy on purpose for each class, document it, and review unused claims and volumes on a regular schedule.

ANTI-PATTERN 04 · A shared network folder for a busy database Avoid
The habit

Choosing a shared file system for everything because it works with any number of pods.

What goes wrong

Databases need low latency and strict write behaviour. A network file system adds delay and locking surprises, which shows up as slow queries and sometimes corrupted files.

Better approach

Give databases a block disk, and keep shared file systems for files that many pods really need to share, such as uploaded media.

13Best Practices and Common Mistakes

These habits come from many teams running stateful applications in production. Follow them and you will avoid most of the painful surprises.

1

Name a class on purpose

Do not depend on an unnamed default. State the class in every claim so it is obvious what you are getting.

2

Use delayed binding for zone-bound disks

Choose the “wait for first consumer” mode so disks are created next to the pods that use them.

3

Allow expansion

Enable volume expansion in the class, start with a sensible size, and grow when monitoring says so.

4

Back up beyond the disk

Take snapshots or backups, store copies in a second place, and test restores regularly.

5

Encrypt and restrict

Turn on encryption in the class, set quotas per namespace, and limit who can touch volumes and snapshots.

6

Monitor capacity and inodes

Alert at 80 percent used and again at 90, and warn when the trend shows the disk filling within days.

7

Clean up regularly

Review claims and volumes that have not been used for weeks, and delete what is truly unneeded after checking backups.

Common mistakes and their cures

MistakeWhat you seeCure
No driver or no default classClaim stays Pending foreverInstall the CSI driver and name a valid class
Wrong access mode for the storageClaim will not bind, or pods cannot start on a second computerMatch the mode to what the storage supports, for example RWX for a shared file system
Disk in the wrong zonePod stays unscheduled with a volume node affinity messageUse delayed binding so the disk follows the pod
Permission denied when writingApplication crashes at startSet the volume group ID and run as a matching user
Database refuses a non-empty folderStartup error mentioning a lost-and-found directoryPoint the database at a sub-folder of the mount
Disk shows free space but writes failErrors about no space leftCheck inodes; too many small files used them all
Trying to shrink a claimChange rejectedCreate a smaller claim and copy the data across
Deleted claim with Delete policyData gonePrevent with Retain and backups; recover from a snapshot
Resize seems ignoredSize grows but the file system does notSome drivers finish growing the file system after the pod restarts
i
A debugging order that works

Check from the claim outward: what is the claim’s status, what do its events say, does a volume exist, is the driver running, did the pod get scheduled, and did the mount succeed? Following the storage’s own path finds the broken link quickly.

14Real-World Usage Stories

Organisations from small start-ups to global enterprises use persistent volume claims. The stories below are simplified illustrations of common situations, not descriptions of any one company’s private setup.

A large online marketplace

Think of a marketplace on the scale of Amazon or Flipkart. Its order database runs as several replicas, each with its own fast block disk in a different zone. A daily snapshot is copied to a second region. During a big sale, the team enlarges the disks in advance so the busiest day never meets a full disk.

A software-as-a-service company

A company selling project-management software gives large customers their own database instance in their own namespace, each with its own encrypted claim. If a customer leaves, the team deletes the namespace, and the storage class removes the disk, which keeps costs tidy. For important accounts they use Retain for a grace period first.

A media website with user uploads

A news or video site lets readers upload photos. Many web pods on many computers must see the same files, so the site uses a shared file system with ReadWriteMany access, such as Amazon EFS. Static images are served through a content delivery network so most reads never reach the cluster.

A machine-learning team

Data scientists need to read very large training data quickly from many pods at once. They use a high-performance shared file system for the data set and fast local or block disks for temporary work. Trained models are saved to a claim and copied to object storage for long-term keeping.

A monitoring stack

Tools that collect metrics, such as Prometheus, and tools that store logs keep their history on claims. When the tool restarts or is upgraded, its history is still there. Teams size the disks by how many days of history they need and expand them as the system grows.

A move from old servers to Kubernetes

A company with an old application on virtual machines copies its data into a new claim, tests the application against that copy, and then switches traffic. Snapshots make it easy to repeat the rehearsal until the final move takes only minutes.

i
Big picture

Across all these stories the same principle repeats: separate the life of the data from the life of the pod, choose storage that fits how the data is used, and always plan for the day something goes wrong.

15Frequently Asked Questions

Q1What is the difference between a PV and a PVC?
A PV is the actual storage in the cluster. A PVC is a request for storage made by an application. Kubernetes binds each claim to one suitable volume, and once bound they belong together until the claim is deleted.
Q2Does deleting a pod delete its data?
No. The data lives on the volume behind the claim, and the claim stays when the pod goes. A new pod that names the same claim sees the same files. Deleting the claim is what can remove the data, depending on the reclaim policy.
Q3What happens if my claim names no StorageClass?
If the cluster has a default class, it is used. If there is no default, the claim waits for a matching pre-made volume and may stay Pending forever. Naming a class explicitly avoids the surprise.
Q4Can two pods use the same claim?
With ReadWriteOnce, pods on the same computer can share it, but pods on different computers cannot. With ReadWriteMany, pods anywhere can share it, if the storage supports that. With ReadWriteOncePod, only a single pod may use it.
Q5Can I make a claim smaller?
No. Kubernetes supports growing volumes but not shrinking them. To reduce size, create a new smaller claim, copy the data into it, and switch the application over.
Q6Can I move a claim to another namespace?
Not directly, because a claim belongs to its namespace. The usual way is to take a snapshot or backup and restore it as a new claim in the target namespace, or to re-attach a retained volume to a new claim with careful manual steps.
Q7Why is my claim Pending even though the class exists?
If the class uses delayed binding, this is normal until a pod that uses the claim is created. Otherwise check the claim’s events: the driver may be missing, permissions may be wrong, the zone may have no capacity, or the requested size or access mode may not be supported.
Q8Are claims backed up automatically?
No. Persistence is not the same as backup. You need scheduled snapshots or a backup tool, and you need to test restoring from them.
Q9How is storage different for a Deployment and a StatefulSet?
A Deployment’s pods usually share one claim you create yourself, or use none. A StatefulSet creates a separate claim for each replica through claim templates, and each replica reconnects to its own claim after a restart. That is why StatefulSets suit databases.
Q10Should I run my database inside Kubernetes at all?
It depends on your team. Running it yourself gives control and portability but makes you responsible for backups, failover and upgrades. A managed database service takes that work away. Many organisations use a managed service for the main database and Kubernetes storage for everything else.

16Summary and Key Takeaways

Key Takeaways

  • Containers forget, PVCs remember. A claim connects a pod to storage that outlives the pod, the container and even the computer.
  • Three objects, three jobs. The PV is the storage, the PVC is the request, and the StorageClass is the menu that describes how storage is created.
  • Pick the access mode and storage type on purpose. Block disks suit single writers such as databases, and shared file systems suit many writers such as uploaded files.
  • Use delayed binding for zone-bound disks. Creating the disk after the pod is placed keeps them in the same availability zone.
  • Reclaim policy decides the fate of your data. Use Retain and backups for anything you cannot afford to lose, and Delete only for disposable data.
  • Persistent is not the same as protected. Take snapshots or backups, keep copies elsewhere, encrypt everything, and test restores.
  • Watch capacity, inodes and pending claims. Alert early, expand before disks fill, and rehearse failure scenarios before they happen for real.