πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Storage beginner ⏱ 15 minutes K8s 1.28+

Kubernetes emptyDir Volume Explained

Use emptyDir volumes in Kubernetes for temporary storage, shared data between containers, and cache. Covers medium types, size limits, and tmpfs backing.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Use emptyDir volumes in Kubernetes for temporary storage, shared data between containers, and cache. Covers medium types, size limits, and tmpfs backing.

The Problem

This is one of the most searched Kubernetes topics. Having a comprehensive, well-structured guide helps both beginners and experienced users quickly find what they need.

The Solution

Basic emptyDir

apiVersion: v1
kind: Pod
metadata:
  name: web-app
spec:
  containers:
    - name: app
      image: my-app:v1
      volumeMounts:
        - name: cache
          mountPath: /tmp/cache
        - name: shared-data
          mountPath: /data
    - name: sidecar
      image: log-shipper:v1
      volumeMounts:
        - name: shared-data
          mountPath: /data    # Same volume β€” shared between containers
  volumes:
    - name: cache
      emptyDir:
        sizeLimit: 500Mi     # Evict pod if exceeded
    - name: shared-data
      emptyDir: {}           # No size limit (uses node disk)

tmpfs (Memory-Backed)

volumes:
  - name: fast-cache
    emptyDir:
      medium: Memory        # RAM-backed β€” ultra fast, counts against memory limits
      sizeLimit: 256Mi

When to Use emptyDir

Use CaseConfiguration
Scratch space / temp filesemptyDir: {}
Shared data between containersemptyDir: {}
Cache directoryemptyDir: { sizeLimit: 1Gi }
High-speed processingemptyDir: { medium: Memory }
Read-only rootfs writable /tmpemptyDir: {} at /tmp
graph TD
    A[emptyDir volume] -->|Created when| B[Pod starts on node]
    A -->|Deleted when| C[Pod removed from node]
    D[Container 1] -->|Read/write| A
    E[Container 2] -->|Read/write| A

Frequently Asked Questions

Does emptyDir persist across container restarts?

Yes β€” emptyDir survives container crashes/restarts within the same pod. It’s deleted only when the pod is removed from the node.

emptyDir vs PVC?

emptyDir is temporary (dies with the pod). PVC persists independently of the pod lifecycle. Use emptyDir for cache/temp, PVC for data that must survive pod deletion.

Best Practices

  • Start simple β€” use the basic form first, add complexity as needed
  • Be consistent β€” follow naming conventions across your cluster
  • Document your choices β€” add annotations explaining why, not just what
  • Monitor and iterate β€” review configurations regularly

Key Takeaways

  • This is fundamental Kubernetes knowledge every engineer needs
  • Start with the simplest approach that solves your problem
  • Use kubectl explain and kubectl describe when unsure
  • Practice in a test cluster before applying to production
#emptydir #volumes #temporary-storage #tmpfs #kubernetes
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens