emptyDir
Estimated time to read: 4 minutes
In Kubernetes, emptyDir
is a type of ephemeral storage that provides a temporary directory shared between all containers in a Pod. This directory is created when the Pod is scheduled to a Node and is deleted when the Pod is removed. The emptyDir
volume is often used for tasks that require temporary storage, such as caching intermediate files or sharing data between containers in the same Pod.
Key Aspects
-
Lifecycle: The
emptyDir
volume is created as soon as the Pod is assigned to a Node and is destroyed when the Pod is deleted. If a container crashes and restarts within the same Pod, the data in theemptyDir
persists across container restarts. -
Storage Medium: By default,
emptyDir
uses the disk of the Node where the Pod is running. You can also specify that theemptyDir
should be memory-backed by setting the medium field to"Memory"
, which causes the data to be stored in RAM. This can provide faster access but at the cost of using up Node memory. -
Usage Scenarios:
- Scratch Space: Temporary files that do not need to persist beyond the Pod's lifetime.
- Data Sharing: Sharing files between containers in the same Pod.
- Caching: Storing intermediate data that can be safely discarded once the Pod is terminated.
Declaratively
-
Empty dir of single pod
-
Run the following command to create
ofl-empty-dir-pod
-
Inspect empty dir
- Run the following command to list the pod
- Run the following command to describe the pod
ofl-empty-dir-pod
- Run the following command to deep dig inside the pod analyses the volume behavior
-
-
Empty dir multi container pod
-
Run the following command to create
ofl-empty-dir-shared-volume
-
Inspect empty dir
- Run the following command to list the pod
- Run the following command to describe the pod
ofl-empty-dir-pod
- Run the following command to deep dig inside the pod analyses the volume behavior
-
Note: All containers in a Pod have read/write access to the same emptyDir - if they requested a mount point for it. Containers can access the emptyDir using the same or different mount points.
Clean up
-
Run the following command to clear all deployment in cluster