Skip to content
beginner Phase 6 · Storage

Volume Types

Explore Kubernetes volume types including emptyDir, hostPath, and projected volumes.

45m
0 problems
Topic Progress 0%

Ephemeral Versus Durable

Ephemeral Versus Durable

Pod storage splits into two lifetimes. Ephemeral volumes live exactly as long as the pod: emptyDir (node disk, or memory with medium: Memory), configMap/secret/projected for read-only config, and the container's own log directory. They vanish on pod deletion and do not follow a rescheduled pod to a new node.

Durable storage belongs to the persistent family (PVCs, covered next), plus hostPath, which pins a node path into the pod.

volumes:
- name: scratch
  emptyDir: { sizeLimit: 2Gi }
- name: cache
  emptyDir: { medium: Memory, sizeLimit: 512Mi }

sizeLimit with ephemeral-storage limits stops a noisy container from filling the node's disk.

hostPath Types and Projections

hostPath Types and Projections

hostPath mounts a node file or directory; its type controls what happens when the path is missing:

type behavior
(empty) no checks
DirectoryOrCreate create the directory if absent
File / FileOrCreate require or create a file
Socket, CharDevice, BlockDevice require that node resource
volumes:
- name: podlogs
  hostPath: { path: /var/log/pods, type: Directory }
- name: combined
  projected:
    sources:
    - configMap: { name: app-config }
    - secret: { name: db-creds }

hostPath couples pods to one node — correct for node agents, wrong for general workloads. Projected volumes merge several sources into a single mount with unified refresh.

Pitfalls and Interview Angles

Pitfalls and Interview Angles

Pitfall 1 — emptyDir as a database. Data dies with the pod and competes with image layers for node disk; node pressure then triggers evictions. Durable state belongs on a PVC.

Pitfall 2 — unrestricted hostPath. Mounting / or the container runtime socket hands the pod node control — which is exactly why Pod Security Standards restrict hostPath.

Interview-ready: sort a workload's data by lifetime (scratch = emptyDir, config = projected, state = PVC), cite medium: Memory as swap-free cache with sizeLimit, and explain why hostPath appears only in node-level DaemonSets.

Quiz

1. Where does emptyDir data go when the pod is deleted?

Question 1 options

2. What does emptyDir medium: Memory do?

Question 2 options

3. Why is hostPath risky for application pods?

Question 3 options

Flashcards

Question

emptyDir lifetime

Answer

Pod lifetime on one node; sizeLimit caps node disk use, medium: Memory switches to tmpfs.

Question

hostPath type field

Answer

Declares whether the node path must exist, may be created, or must be a file/device.

Question

projected volume

Answer

Merges ConfigMaps, Secrets, Downward API, and service account tokens into one mount.

Question

ephemeral vs persistent

Answer

Ephemeral dies with the pod; persistent volumes survive rescheduling via PVCs/PVs.

Revision Notes

Key Takeaways

  • 1. Classify storage by lifetime before choosing a type
  • 2. emptyDir is scratch space; hostPath is for node agents only
  • 3. Projected volumes unify config sources under one mount

Interview Tips

  • • Give the scratch/config/state sorting rule with examples
  • • Explain why security policies restrict hostPath with a concrete attack

Cheat Sheet

emptyDir = pod-lifetime scratch (sizeLimit, medium: Memory); hostPath = node-bound, restricted; projected = merged sources. State belongs on PVCs.

Continue Learning