Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 61/ 160
04. Storage & Persistent Data

Ephemeral Storage (emptyDir & Memory-Backed emptyDir)

Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data.

BeginneremptyDir · Ephemeral · tmpfs3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 yaml and 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

Loading interactive 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.

Verify Ephemeral, not only object creation

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.

Key takeaway: emptyDir is implemented only when this invariant remains observable: 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.

Recover from Ephemeral drift

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.

Key takeaway: Accept the trade-off consciously: Shared Pod-local scratch avoids external storage, but it is neither replicated nor durable across node rescheduling.

How it works, step by step

Step 1 of 4
Data owner

1. 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.

emptyDir contract → owned state
Key numbers at this step
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 yaml in 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 yaml first: 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

Dynamically provisioned storage
Best for: Use emptyDir for scratch space and memory-backed volumes for fast ephemeral data. A concrete incident check is 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.

Manual pre-provisioning
Best for: Quickly testing the Ephemeral assumption with 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.

Managed external data plane
Best for: Teams that need tmpfs integrated with guardrails; the evidence path is 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 yaml without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Service Mesh Introduction (Istio & Linkerd: mTLS, Retries, Circuit Breaking)
Next topic
hostPath & Local Volumes (Use Cases & Security Risks)