Mastering Kubernetes One Task at a Time — Ephemeral Storage Volumes with ‘emptyDir’
3 working examples demonstrate three ways of configuring emptyDir Volumes meeting three specific purposes. Learn all of them right here!
Table of Contents
- Introduction
- Kubernetes Documentation References for emptyDir
- Create and Access KIND Kubernetes Cluster on EC2
- OBJECTIVE 1 — Communicate Between Containers Using emptyDir Shared Volume
- OBJECTIVE 2 — Implment Memory or RAM-backed emptyDir Volume
- OBJECTIVE 3 — Setting emptyDir Volume sizeLimit and Ephemeral Storage Resource Requests and Limits
- Conclusion

Introduction
Persistent Storage Volumes with ‘hostPath’ post last week broke ground in the Mastering Kubernetes One Task at a Time series by showing how to define volumes in a pod, configure volumeMounts inside containers, and use the hostPath type to meet persistent storage needs using the cluster node filesystem. Having acquired the skills, we’re ready to showcase many other types of Volumes and apply them to meet various needs in everyday Kubernetes applications. Please follow the link below to read and try out the hands-on examples.
This post lines up the next logical Volumes type we want to cover, called emptyDir, an important implementation of Kubernetes that exists for a few special reasons outlined in the next section with associated references. This Volumes type is ephemeral, which means its lifetime is limited to a Pod’s lifetime, and all containers in the Pod can read and write the same files in the emptyDir Volume. When a pod ceases to exist, Kubernetes destroys all ephemeral volumes.
Here I’ll cover the following 3 demonstrations or objectives that I think are must-know initial skills to take full advantage of emptyDir volumes.
- Enable inter-container communication in the same Pod using a shared Volume where data should not persist outside the Pod’s existence.
- Implement a memory or RAM-backed filesystem using emptyDir because data is not permitted to be written on the disk.
- Show how to restrict emptyDir volume size limit as well as how to specify ephemeral storage resource requests size and resource limit size.
Kubernetes Documentation References for emptyDir
The following links from the kubernetes.io documentation site provide sufficient ground to understand the purpose, use cases, and implementation tips and examples. Next, refer to my summary below for a quick grasp. As always, it’s best to read up first and then try the hands-on examples to comprehend and internalize the concepts and the constructs fully.
- Kubernetes Volumes emptyDir type — https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
- Types of Ephemeral Volumes —https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#types-of-ephemeral-volumes
- Volumes Local / Temporary Directory API Spec — https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/volume/#local-temporary-directory
In practice, emptyDir Volumes types are commonly used for—
- Scratch space requirements, such as for a disk-based merge sort
- Checkpointing a long computation for recovery from crashes by creating log files
- Holding files that a content-manager container (a sidecar container pattern) fetches while a webserver container serves the data
One of my hands-on examples below shows the use of emptyDir.medium: Memory setting, which lets Kubernetes mount a tmpfs (RAM-backed filesystem). The Kubernetes resource secret, usually used to pass sensitive information, such as passwords, can be mounted to Pods as Volumes. The secret volumes are backed by tmpfs (memory) so they are never written to non-volatile storage.
Finally, as resource management best practice, ephemeral storage resource requests, limits, and emptyDir size limit settings are set, similar to CPU and memory resource management. The third objective hands-on example shows how to implement and test these features.
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.
NOTE: I have a Kubernetes Cluster (1 control plane and 2 worker nodes) with Kubeadm using Terraform and AWS EC2 that can also be used for hands-on exercises as an alternative.






