Creating persistent local-storage volume in Kubernetes
PersistentVolume and PersistentVolumeClaim in kubernetes provides a way to allocate storage for the pods. Kubernetes PV supports different types of storage. Now here in the below post we are going to use storage-class local-storage and watch the behaviour for different reclaimpolicy.
I am using the Virtualbox(running in Ubuntu 18.04 physical machine) for this entire setup . The physical machine is Dell inspiron laptop with 12GB RAM , Intel® Core™ i7-6500U CPU @ 2.50GHz × 4 and 512GB SSD hardisk.
Step 1: Create a directory in one for the node and add a file
Step 2: Get the label of the node
We need to get the label of the node where the directory is created.This we need to configure in the nodeAffinity specs in order to properly stick the pod to respective node where the local volume is present.
Step 3: Create a persistent volume(PV)
Create a PV and map the local storage director and configure the label in the node selector
Step 4: Verify the PV status
Verify the PV status. It is currently configured with access type RWO and reclaim policy as Delete
Step 5: Create a persistent volume claim(PVC)
Create a PVC and map the above created PV
Step 6: Verify the PVC status
Verify the PVC and PV status. Now we can see the status changes from Available to Bound.
Step 7: Create a pod and map the PVC
Create a pod and map the volumes as below
Step 8: Verify the pod status and volume inside
Verify the status of the new pod and check the volume is mounted inside the container
Now we can see the directory from the PV is mounted in the pod and the files created are present
Verify reclaim policy(Below steps are Optional)
Step 9: Delete PVC and verify PV
Now delete the pod and PVC and verify the status of PV
We can see the staus of PV is automaticall changed to Failed. This is due the the reclaim policy Delete
Step 10: (Optional ) Try recreate PVC
We can optionally try recreating the PVC volume and verify the status
We can see the status of PV is still Failed and the PVC always in Pending and never creates
Step 11: Delete and create PV with reclaim policy as retain
Now lets clean up all PV and PVC and recreate PV with reclaim policy set as “Retain”
Step 12: Delete the PVC and verify the status of PV
Now lets delete the PVC and verify the status of the PV
Now we can see the status of PV changes to “Released” instead of “Failed” due to the reclaim policy “Retain”