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
hostPath
volume in the pod template - Directory location for
hostPath
volume on host is/data
- The pod has only one container
- The
hostPath
volume is mounted on/my-data directory
of the container - The container writes some data in the
my-persistent-data.txt
file 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-data
directory is present in the container: -
View the content of
/my-data/my-persistent-data.txt
file:
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
/data
directory is present and hasmy-persistent-data.txt
file in it: -
View the content of
/data/my-persistent-data.txt
file:
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: