Understand how Kubernetes provides persistent storage to Pods using:
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.
The PV pointed to a HostPath directory:
/mydata
This directory resides on the worker node and stores the data.
The PVC was bound to the PV:
PV → PVC
Once bound, a Pod can request storage through the PVC.
The Pod mounted the PVC at:
/usr/share/nginx/html
Anything written to this directory is actually written to the PV.
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
This proves the Pod was writing data to the Persistent Volume.
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 lab required creating:
/storage/index.html
containing:
hello lab11
Then verifying its existence from inside the Pod.
kubectl exec -it test-pv-pod -- sh -c \ 'echo "hello lab11" > /usr/share/nginx/html/index.html'
kubectl exec -it test-pv-pod -- ls -l /usr/share/nginx/html
kubectl exec -it test-pv-pod -- cat /usr/share/nginx/html/index.html
Expected output:
hello lab11
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:
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.