Lesson 11 Study Notes: Persistent Volumes and Persistent Volume Claims

Objective

Understand how Kubernetes provides persistent storage to Pods using:


Storage Flow

Host Directory (/mydata)
          ↑
PersistentVolume (PV)
          ↑
PersistentVolumeClaim (PVC)
          ↑
Pod
          ↑
/usr/share/nginx/html

Think of a PVC as a storage request and a PV as the actual storage resource.


What the Lab Demonstrated

1. Created a Persistent Volume

The PV pointed to a HostPath directory:

/mydata

This directory resides on the worker node and stores the data.

2. Created a Persistent Volume Claim

The PVC was bound to the PV:

PV  →  PVC

Once bound, a Pod can request storage through the PVC.

3. Mounted the Storage into an Nginx Pod

The Pod mounted the PVC at:

/usr/share/nginx/html

Anything written to this directory is actually written to the PV.


Proof that the Volume Worked

Inside the Pod:

kubectl exec -it test-pv-pod -- touch /usr/share/nginx/html/new

On worker1:

ls -l /mydata

Output showed:

hello
hellofile
hellofucker
new
Success: The file created inside the Pod appeared in the HostPath directory on the worker node.

This proves the Pod was writing data to the Persistent Volume.


Why This Matters

Containers are temporary.

If data is stored only inside a container filesystem:

Pod Deleted → Data Lost

If data is stored on a PV:

Pod Deleted → Data Remains

A new Pod can mount the same PVC and continue using the files.


The Missing Lab Step

The lab required creating:

/storage/index.html

containing:

hello lab11

Then verifying its existence from inside the Pod.

Create the File

kubectl exec -it test-pv-pod -- sh -c \
'echo "hello lab11" > /usr/share/nginx/html/index.html'

Verify the File Exists

kubectl exec -it test-pv-pod -- ls -l /usr/share/nginx/html

Verify the Contents

kubectl exec -it test-pv-pod -- cat /usr/share/nginx/html/index.html

Expected output:

hello lab11

Common Error Encountered

Error:

pod test-pv-pod does not have a host assigned

Cause:

persistentvolumeclaim "test-pv-claim" not found

The Pod could not be scheduled because the referenced PVC did not exist.

Fix:


Exam/Interview Takeaway

A Persistent Volume provides storage.

A Persistent Volume Claim requests storage.

A Pod mounts the PVC to access the storage.

Data written through the mounted path persists even if the Pod is deleted and recreated.

One-Sentence Summary

The purpose of the lab was to demonstrate that a Kubernetes Pod can write data to a Persistent Volume through a PVC, allowing the data to survive beyond the lifetime of the Pod.