Introduction
Welcome back to our Kubernetes journey! Today, Let's explore the world of Persistent Volumes (PV) and how they play a crucial role in ensuring data persistence in your deployments. In this task, we will walk through the process of adding a Persistent Volume to your Todo app deployment.
TASK 1: What are Persistent Volumes in k8s?
Before we get our hands dirty, let's understand what Persistent Volumes are in Kubernetes. In simple terms, PVs are storage resources that exist independently of any pod, ensuring that your data survives pod restarts and rescheduling.
TASK 2: Add a Persistent Volume to your Deployment Todo app
Task 2.1: Create a Persistent Volume using a file on your node ๐
To kick things off, we'll create a Persistent Volume using a file on our node. This file will act as our storage resource.
kubectl apply -f pv.yaml
verify pv:
kubectl get pv -n django-name
Task 2.2: Create a Persistent Volume Claim (PVC) ๐
Now, let's create a PVC that references the Persistent Volume we just set up. This claim is like a request for storage, specifying the requirements needed.
kubectl apply -f pvc.yaml
verify pvc:
kubectl get pvc -n django-name
Task 2.3: Update your deployment.yml file ๐ ๏ธ
With our PV and PVC in place, it's time to update our deployment configuration to include the PVC. This ensures that our app uses the persistent storage we've set up.
Task 2.4: Apply the updated deployment ๐ข
Execute the command kubectl apply -f deployment.yml
to apply the changes to your deployment. This brings our persistent storage into action.
kubectl apply -f deployment.yaml
kubectl get pods
Task 2.5: Verify the Persistent Volume in your Deployment ๐ต๏ธโโ๏ธ
Use kubectl get pods
to check the status of your pods and ensure that the Persistent Volume has been successfully integrated.
Task 3: Accessing data in the Persistent Volume
Task 3.1: Connect to a Pod in your Deployment ๐
We're getting hands-on! Use kubectl exec -it -- /bin/bash
to connect to a pod in your deployment and explore what's happening inside.
kubectl exec -it <pod-name> -- /bin/bash
Task 3.2: Verify data access in the Persistent Volume ๐พ
Ensure that you can access the data stored in the Persistent Volume from within the pod. This step confirms that our persistent storage is functioning as expected.
Conclusion
Congratulations! ๐ You've successfully added persistent storage to your Kubernetes deployment. By understanding and implementing Persistent Volumes, you've taken a big step towards making your applications more robust and data-resilient. Stay tuned for more Kubernetes adventures! ๐ข๐