The context introduces the concept of Kubernetes Volumes and their usage with 'hostPath' for persistent storage, demonstrating practical examples and objectives.
Abstract
The context discusses Kubernetes Volumes and the 'hostPath' volume type, which allows users to mount a file or directory from the cluster node's filesystem into a pod. The document highlights the importance of understanding and working with Volumes for handling persistent data storage and sharing data between containers hosted inside a single pod. The text provides practical examples and three objectives, including creating persistent volumes, using multiple volumes and volume mounts in a pod, and sharing volumes among multiple containers.
Opinions
The author believes that mastering the concept of Kubernetes Volumes and 'hostPath' is essential for working with Storage resources and other Kubernetes resources like ConfigMaps and Secrets.
The author mentions that using 'hostPath' for persistent data storage is not the best way and has security consequences, but it can still be useful for specific demands of a Kubernetes application and cluster operations as long as the risks are understood and safely implemented.
The author suggests using the KIND cluster for hands-on activities related to Volumes.
The author emphasizes the importance of understanding the use of 'volumes' and 'volumeMounts' constructs inside a pod to manage different types of Kubernetes Volumes and leverage them for the different needs of containers running inside a pod.
The author encourages readers to practice the hands-on examples provided to thoroughly understand and know how to use the cluster node filesystem for persistent data storage.
The author recommends following the series and staying in touch for more information on Kubernetes.
The author appreciates readers' support and encourages them to share the post to help others.
Mastering Kubernetes One Task at a Time — Persistent Storage Volumes with ‘hostPath’
3 objectives teaching pod Volumes, container volumeMounts and handling of persistent data on Kubernetes cluster node filesystem with hostPath.
Mastering Kubernetes One Task at a Time — Persistent Storage Volumes with ‘hostPath’
Introduction
Know Thy Nodes!post in the Mastering Kubernetes One Task at a Time series was a timely and logical segue to help build up the skills necessary to leverage while architecting, implementing, debugging, and troubleshooting complex applications with advanced and broad use of Kubernetes resources. I hope you had a chance to try out all the six objectives covered. If not, please follow the link below to check it out.
This post, Persistent Storage Volumes with ‘hostPath’, introduces the first of several Kubernetes Storage related concepts and building blocks. It’s essential to master these introductory skills at this point of the game because knowing how to create Volumes in pods and mount Volumes inside containers is helpful to work with Storage resources as well as resources like ConfigMaps and Secrets, which are next in my task roster.
Kubernetes Volumes Resource Reference
Two Kubernetes.io official documentation pages are worth reviewing to understand and work with Volumes. A quick reading to begin with, followed by more back-and-forth reading while doing hands-on work, is the best approach to learning the different parts these pages cover.
The main summary takeaways for the purpose of working with Volumes and de>hostPath Volumes type from these pages is the following:
Volume abstraction solves two critical necessities in the Kubernetes world. First, the need to persist data beyond a container’s life period because when a container is lost (crashed and died or intentionally terminated), its filesystem and stored data are also wholly lost. Volumes provide the means to store data outside of the container filesystem. Second, Volumes enable data sharing between containers hosted inside a single Pod.
A hostPath volume mounts a file or directory from the cluster node’s filesystem into a Pod. This is not the best way to handle the need for persistent data storage, and it does have security consequences, but the feature does provide the convenience of tapping into the node filesystem for specific demands of a Kubernetes application and cluster operations as long as the risks are understood and safely implemented.
Let’s get a hands-on appreciation of this new functionality, its capabilities, and its potential in the large Kubernetes scheme.
Create and Access KIND Kubernetes Cluster on EC2
It turns out our faithful KIND cluster, as detailed in the blog post The AWS Way — IaC in Action — A Docker and KIND Ready Amazon EC2 Node,is fully able to support all the Volumes-related hands-on activities. So, without further ado, let’s use the code below to fire up the cluster and access it to execute our code, including my demonstration objective by objective.
OBJECTIVE 1 — Creating Persistent Volumes on Cluster Node Filesystem
Kubernetes, for any kind of volume in a given pod, does not destroy persistent volumes but preserves the data across container restarts.
The code below demonstrates the above claim with hostPath Volumes type in two ways:
Create a deployment with each of its replica pods running on each available cluster worker node. When a pod is manually terminated, the deployment automatically creates a new one, and we see that the pod can continue its work on the same data file.
After the deployment is created, we also see that the data file exists in the node filesystem.
OBJECTIVE 2 — Using Multiple Volumes and Volume Mounts in a Pod
Having demonstrated the workings of volumes and volumeMounts, and knowing how to use these directives in a Pod manifest, we can now go a step further to showcase the versatility of the Volumes design.
A pod can have multiple volumes present, and containers in the pod have the complete liberty to mount the available volumes in different locations with different names or not mount at all. Once mounted, the container can operate on the storage primitives normally within the boundary of permission assigned.
OBJECTIVE 3 — Sharing Volumes among Multiple Containers
The code below implements a common practical need in Kubernetes applications, i.e., to be able to share data among multiple containers. Volumes help accomplish this objective in two ways— persistent data sharing and ephemeral data sharing. I’ll cover the ephemeral topic in the next post. Since hostPath type uses the cluster node filesystem, this is an easy way to share data among the containers of a pod.
Conclusion
Storage Management in Kubernetes is a broad and complex area. The Persistent Storage Volumes with ‘hostPath’ is the first introduction of this area in the Mastering Kubernetes One Task at a Time series.
Using the hands-on examples of this introductory post, you’ll learn how to use volumes and volumeMounts constructs inside a pod to manage different types of Kubernetes Volumes and how to leverage them for the different needs of containers running inside a pod.
After practicing the hands-on examples of all three objectives covered here, you’ll thoroughly understand and know how to use the cluster node filesystem for persistent data storage toward the end goal of retaining data beyond the pod and container lifecycles and sharing data among the containers within a pod.
Thank you for following the series and staying in touch.
Please follow to stay in touch, track, and be the first to get notified of all future writings on AWS Cloud, Containers, Kubernetes, and Machine Learning. Also, check all my stories on The AWS Way publication.