Mastering Kubernetes Pod Configuration: Persistent Data
Kubernetes provides a variety of features to get the most out of your containerized applications. This lab will train you on Pod configuration concepts that teach you how to persist data beyond the li
Walkthrough
Create a Namespace for the resources you'll create in this lab step and change your default kubectl context to use the Namespace.
Create a PVC
pvc.yaml
Create pod from pvc.yaml
You will use the PVC to store data in a database, a common example of persistent data that should survive in case a Pod were to be terminated. Use get to display the PVC.
pvc is a kubectl alias for persistentvolumeclaim, so you don't need to type the complete Resource name. The output shows the PVC STATUS is Bound, but the output may show Pending while the underlying PV is being created. The STORAGECLASS is gp2 which is the type of automatically configured Amazon EBS volumes that are created. Use get to display the underlying PV.
Similar information is displayed. There is a RECLAIM POLICY associated with the PV. The Delete policy means the PV is deleted once the PVC is deleted. It is also possible to keep the PV using other reclaim policies. Create a Pod that mounts the volume provided by the PVC.
db.yaml
The Pod uses the MongoDB image, which is a NoSQL database that stores its database files at /data/db by default. The PVC is mounted as a volume at that path causing the database files to be written to the EBS Persistent volume. Run the MongoDB CLI client to insert a document that contains the message "I was here" into a test database and then confirm it was inserted:
Delete the Pod. At this point, a regular (emptyDir) volume would be destroyed and the database files would be lost.
Create a new database Pod. Although the Pod is new, the Pod's spec refers to the same PVC as before.
Attempt to find a document in the test database. The output confirms the data was persisted by using the PVC.
Last updated