Ephemeral Storage (emptyDir & Memory-Backed emptyDir)
Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data.
In plain words
emptyDir is a shared whiteboard for one Pod's work session, erased when the group leaves and optionally stored as fast volatile memory. The simple Kubernetes rule is: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Think of it like…
emptyDir is a shared whiteboard for one Pod's work session, erased when the group leaves and optionally stored as fast volatile memory.
Where you’ve seen it
Before approving a data-path change, the storage owner runs kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml. Expected evidence: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits. If the run instead shows this symptom, stop and restore the last known state: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
Words you’ll hear
- emptyDir
- For this lesson, emptyDir is the controlling idea: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Ephemeral
- Ephemeral is the checkpoint; run
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yamland inspect the owner chain. Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill. - tmpfs
- tmpfs is the outcome to preserve; the cost is explicit: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
- Verification evidence
- The evidence command is
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml. It connects the declaration to this behavior: Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data.
Visual diagram
Theory & deep dive
How emptyDir reaches the intended state
Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data. An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
The concrete checkpoint is kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml; compare the emptyDir owner, Ephemeral state, and tmpfs outcome instead of treating YAML acceptance as proof.
Run kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml after the change and correlate the result with Events and the owning object. An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Ephemeral: failure boundary and production cost
Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill. The prerequisite contract is concrete: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling. A safe design limits blast radius, records the last good configuration, and uses kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml as a deterministic rollback checkpoint.
Capture the current state with kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
How it works, step by step
Step 1 of 41. Declare the data contract
State capacity, topology, access, and ownership in the claim or class: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Goal
- Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data.
- Owner
- emptyDir
When to use it & trade-offs
What it is
Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data. An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Why it matters: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill. The invariant at risk is specific: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits. The quickest fact check before changing the design is kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml.
When to reach for it
- Use emptyDir to enforce this invariant: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Use Ephemeral evidence from
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yamlin reviews and incident timelines. Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data. - Choose the managed external data plane route only when this cost is justified by governance or scale: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
When to avoid or be careful
- Avoid assuming emptyDir is complete after YAML submission; the required behavior is concrete: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Avoid treating the next symptom as random; check the owner and state with
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yamlfirst: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill. - Avoid adopting a heavier platform wrapper before measuring its cost: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
Native, manual, and managed paths for emptyDir
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml.Strengths: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Watch out: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling. Recovery must also recognize this signal: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml; the expected invariant is: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.Strengths: kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike emptyDir, it does not make this symptom self-documenting: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
Watch out: The added platform ownership buys value at this cost: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Trace emptyDir to tmpfs through Ephemeral; the invariant is: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Recognize the symptom: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
- Justify the cost: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
- Verify with kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml instead of only inspecting YAML.
Benchmarks & rules of thumb
- 1
- Pod lifetime owns the emptyDir
- 0
- durability across Pod replacement
- 2
- emptyDir media choices are disk and Memory-backed tmpfs
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the emptyDir owner contract: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits.
- Ignoring this telltale condition leads to unrelated changes: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill.
- Repeating
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yamlwithout an owner for remediation wastes retry cost. Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits?
- Which owner object, logs, and Events would you inspect for this symptom-Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill-?
- At what threshold would this cost become unacceptable: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling?
kubectl exec scratch-0 -- df -h /cache; kubectl get pod scratch-0 -o yaml, name the failure, then justify the cost. Invariant: An emptyDir is created for a Pod, survives container restarts on that node, and disappears with the Pod; medium Memory maps the volume to tmpfs and counts against container memory limits. Failure: Without ephemeral-storage requests, a writer can consume node disk and trigger DiskPressure eviction; memory-backed emptyDir that grows too large can cause an OOM kill. Cost: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Ephemeral Storage (emptyDir & Memory-Backed emptyDir) with generative AI interview Q&A and hands-on practice.