Kubernetes emptyDir volumes: Use cases and examples
Learn how Kubernetes emptyDir volumes work with practical examples. Covers disk-backed and memory-backed options, shared storage between containers, and typical use cases.
5 lessons · 16 min · Intermediate
Written by
Marketing Team at Civo
Written by
Marketing Team at Civo
Before diving into emptyDir specifically, here is a quick overview of where it fits in the Kubernetes volume landscape:
What is emptyDir?
An emptyDir volume is created fresh when a pod is assigned to a node. It exists for the entire lifetime of that pod and is deleted when the pod is deleted.
The key distinction is that emptyDir is pod-scoped, not container-scoped. If a container inside the pod crashes and restarts, the emptyDir volume and all its data are still there when the container comes back up. The data is only lost when the entire pod is deleted. This makes emptyDir useful for data that needs to survive container restarts but does not need to outlive the pod.
By default, emptyDir uses the node's disk. You can optionally back it with node RAM for faster access.
Common use cases
- Shared scratch space between containers in the same pod: A main application container writes files to an emptyDir and a sidecar container reads from the same directory. This is a common pattern for log shipping: the application writes logs to /var/log/app and a Fluentd or Filebeat sidecar reads from the same path and forwards them to a logging backend.
- Caching downloaded assets: A pod that processes files can download them into an emptyDir in an init container and then process them in the main container, avoiding repeated downloads across processing steps.
- Temporary file processing in a batch pipeline: Intermediate files generated during a multi-stage processing job can live in an emptyDir between stages. When the pod completes, the files are cleaned up automatically.
- Checkpointing long computations: A computation that runs in stages can write checkpoints to an emptyDir so that if a container crashes mid-computation, it can resume from the last checkpoint rather than starting over.
Basic emptyDir example
apiVersion: v1kind: Podmetadata:name: emptydir-podspec:containers:- name: busyboximage: busyboxcommand: ["sh", "-c", "while true; do sleep 3600; done"]volumeMounts:- mountPath: /demoname: demo-volumevolumes:- name: demo-volumeemptyDir: {}
kubectl create -f pod.yamlkubectl get pods
Exec into the pod and create a file:
kubectl exec -it emptydir-pod -- sh
cd /demotouch testls
Expected output:
test
Exit the pod and verify the file exists from outside:
kubectl exec -it emptydir-pod -- ls /demo
Expected output:
test
Delete the pod:
kubectl delete pod emptydir-pod --force --grace-period=0
The emptyDir and all its contents are deleted with the pod. There is nothing to clean up manually.
Sharing an emptyDir between two containers
This example shows a sidecar pattern. The main container writes a timestamp to a shared log directory every five seconds. The sidecar container reads from the same directory.
apiVersion: v1kind: Podmetadata:name: shared-volume-podspec:containers:- name: writerimage: busyboxcommand: ["sh", "-c", "while true; do date >> /shared/log.txt; sleep 5; done"]volumeMounts:- mountPath: /sharedname: shared-data- name: readerimage: busyboxcommand: ["sh", "-c", "while true; do cat /shared/log.txt; sleep 10; done"]volumeMounts:- mountPath: /sharedname: shared-datavolumes:- name: shared-dataemptyDir: {}
kubectl create -f shared-volume-pod.yaml
Check the reader container's logs to see the timestamps being written by the writer container:
kubectl logs shared-volume-pod -c reader
Expected output:
Thu Jan 15 10:23:01 UTC 2026Thu Jan 15 10:23:06 UTC 2026Thu Jan 15 10:23:11 UTC 2026
Both containers share the same /shared directory via the emptyDir volume. Data written by one is immediately visible to the other.
Memory-backed emptyDir
Set medium: Memory to back the emptyDir with node RAM instead of disk. This gives you tmpfs storage, which is significantly faster than disk for workloads that need very fast temporary storage.
apiVersion: v1kind: Podmetadata:name: memory-volume-podspec:containers:- name: busyboximage: busyboxcommand: ["sh", "-c", "while true; do sleep 3600; done"]resources:limits:memory: 256MivolumeMounts:- mountPath: /cachename: cache-volumevolumes:- name: cache-volumeemptyDir:medium: MemorysizeLimit: 128Mi
Two important things to note with memory-backed emptyDir:
The volume size counts against the container's memory limit. In the example above, the container has a 256Mi memory limit. If the emptyDir uses 128Mi of that, only 128Mi remains for the application itself. Size it carefully.
Use sizeLimit to cap how much RAM the emptyDir can consume. Without it, the volume can grow until it hits the container's memory limit, which will trigger an OOMKilled event.
kubectl create -f memory-volume-pod.yamlkubectl exec -it memory-volume-pod -- df -h /cache
Expected output:
Filesystem Size Used Avail Use% Mounted ontmpfs 128M 0 128M 0% /cache

Marketing Team at Civo
Civo is the Sovereign Cloud and AI platform designed to help developers and enterprises build without limits. We bridge the gap between the openness of the public cloud and the rigorous security of private environments, delivering full cloud parity across every deployment. As a team, we are dedicated to providing scalable compute, lightning-fast Kubernetes, and managed services that are ready in minutes. Through CivoStack Enterprise and our FlexCore appliance, we empower organizations to maintain total data sovereignty on their own hardware.
Our mission is to make the cloud faster, simpler, and fairer. By providing enterprise-grade NVIDIA GPUs and streamlined model management, we ensure that high-performance AI and machine learning are accessible to everyone. Built for transparency and performance, the Civo Team is here to give you total control over your infrastructure, your data, and your spend.
Share this lesson