QA
Senior LevelDocker & Deployment

How does emptyDir: { medium: "Memory" } create high-speed RAM disks inside pods?

❓ Interview Prompt: Explain emptyDir tmpfs RAM disks, memory limits interaction, use cases for caching and IPC, and ephemeral storage quotas.

emptyDir volumes are ephemeral scratch space created when a pod starts and deleted when a pod terminates. By default, emptyDir is stored on the node's disk (or SSD). Setting medium: Memory mounts a tmpfs (RAM-backed) filesystem instead.

tmpfs Performance Characteristics:

•
Read/write speed: RAM bandwidth (~40 GB/s) vs NVMe SSD (~7 GB/s) vs spinning disk (~200 MB/s).
•
Latency: Nanoseconds vs microseconds vs milliseconds.
•
Volatile: Data is lost when the pod is deleted or the node reboots.

Critical Interaction with Memory Limits:

tmpfs storage counts against the container's memory limit. If a container has memory: 1Gi limit and writes 800MB to tmpfs, it has only 200MB of RAM left for its process — the OOM killer may trigger.

Always account for expected tmpfs usage when setting memory limits.

Use Cases:

1
Inter-process communication (IPC): Share data between sidecar containers at RAM speed.
2
Temp file caching: ML model inference — cache model weights in RAM between requests.
3
Sensitive secrets: Write Vault secrets to tmpfs (not to disk — harder to recover after pod deletion).
4
Compilation scratch: Fast compilation temp directories (C/C++ builds).

Code Implementation Example

yaml
apiVersion: v1
kind: Pod
spec:
  containers:
    - name: app
      image: myapp:v1.2.3
      resources:
        limits:
          memory: "2Gi"    # Total: 1.5GB process + 512MB tmpfs
          cpu: "1"
      volumeMounts:
        - mountPath: /tmp/cache
          name: ram-cache     # RAM disk for high-speed caching
        - mountPath: /dev/shm
          name: shm           # POSIX shared memory for IPC
        - mountPath: /tmp/secrets
          name: secret-tmpfs  # Secrets in RAM — not on disk
    
    - name: sidecar
      image: metrics-sidecar:latest
      volumeMounts:
        - mountPath: /shared
          name: ram-cache    # Both containers share the RAM disk

  volumes:
    # tmpfs RAM disk — 512MB limit (counts toward memory limit!)
    - name: ram-cache
      emptyDir:
        medium: Memory
        sizeLimit: 512Mi    # OOM if exceeded, not disk overflow

    # Shared memory for POSIX IPC between sidecar containers
    - name: shm
      emptyDir:
        medium: Memory
        sizeLimit: 256Mi

    # Regular emptyDir (disk-backed) for temp files
    - name: secret-tmpfs
      emptyDir:
        medium: Memory
        sizeLimit: 10Mi
💡tmpfs emptyDir: 512MB RAM disk for caching, 256MB /dev/shm for IPC — both count toward the 2Gi memory limit.
🎯 Interview Key Takeaway

emptyDir medium:Memory creates tmpfs RAM disks — 10-100x faster than disk. CRITICAL: tmpfs counts against container memory limits. Set sizeLimit to prevent unbounded RAM consumption.

#Kubernetes#emptyDir#tmpfs#RAM Disk#Performance#Senior
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?