hostPath Volume Demo¶
Let's see how we can use emptyDir volume as temporary storage.
Here is the Docker Image used in this tutorial: reyanshkharga/nginx
Step 1: Create a Deployment With hostPath Volume¶
Let's create a deployment as follows:
Observe the following:
- We have added an
hostPathvolume in the pod template - Directory location for
hostPathvolume on host is/data - The pod has only one container
- The
hostPathvolume is mounted on/my-data directoryof the container - The container writes some data in the
my-persistent-data.txtfile every 5 seconds
Apply the manifest to create the deployment:
Step 2: Verify Deployment and Pods¶
Step 3: Verify Volume Mount and Data¶
Let's verify if the hostPath volume was mounted in the container.
-
Start a shell session inside the container:
-
Verify if
/my-datadirectory is present in the container: -
View the content of
/my-data/my-persistent-data.txtfile:
Step 4: Verify hostPath Volume on Worker Node¶
Let's verify if the /data directory was created on the host machine where the pod is running.
-
Find node where the pod is running:
-
Access the worker node (EC2 Instance) by logging in through SSH or session manager.
-
Verify if
/datadirectory is present and hasmy-persistent-data.txtfile in it: -
View the content of
/data/my-persistent-data.txtfile:
Step 5: Delete the Deployment¶
Let's delete the deployment and see what happens to the hostPath volume.
Step 6: Verify hostPath Volume on Worker Node Again¶
Access the node by logging in through SSH or session manager and verify if the data persists.
Observation:
- The directory and files created by pods persists
- Any data generated by pods persists.
Clean Up¶
Assuming your folder structure looks like the one below:
Let's delete all the resources we created: