HostPath Volume

Step 1: Verify the volume folder is available on all the nodes of Kubernetes Cluster

ls /mnt/data/vol

Step 2: Create a Persistent Volume

kubectl create -f 01-Persistent-Volume.yaml

Step 3: Verify the Volumes

kubectl get pv

Step 4: Show more details about the Volume

kubectl get pv vol-x -o yaml

Step 5: Create Persistent Volume

kubectl apply -f 02-Persistent-Volume-Claim.yaml

Step 6: Verify the PVC Status

kubectl get pvc

Step 7: Describe and Verify the PVC

kubectl describe pvc http-claim

Step 8: Create and Run the application pod

kubectl apply -f 03-app.yaml

Step 9: Now try to access the pod and see the application

  • See on which Worker Node the pod is scheduled

  • If the Pod is Scheduled on Worker1, then login to the specific worker node and perform below steps

Step 9: Add data to the Volume

Give permissions

sudo chmod 777 /mnt/disk/vol
echo "Hello Team, How are you Doing" > /mnt/data/vol/index.html

Access the Pod IP using CURL and check the output

Sample CURL Statement : curl http://nodeip

Step 11: Now Lets change the Value, by being inside the container

echo "Changed the content from container" > /usr/share/nginx/html/index.html

Access the Pod IP using CURL and check the output

Sample CURL Statement : curl http://nodeip

Step 12: Lets Delete the Pod and see weather data persists or not

kubectl delete pod www

Step 13: Check PVC

kubectl get pvc

Step 14: Create a new pod with older Volume

kubectl apply -f 04-newpod.yaml

Step 15: Verify weather we are able to read the index.html using the new pod

kubectl logs centos

See on which Worker Node Centos Pod is scheduled and then accordingly run the commands

Clear Everything in the current namespace

kubectl delete all --all -n default
kubectl delete pvc --all
kubectl delete pv --all

Run the Below command on those Nodes, where you have created the mount path.

If you are not aware then run this below command on all the nodes.

sudo rm -rf /mnt/data

Last updated

Was this helpful?