liveBook · Manning

Emptydir volume

As explained in Kubernetes for Developers

emptyDir is a Kubernetes volume type that provides temporary node-backed storage for a Pod and is deleted when the Pod leaves the node.

An emptyDir volume gives containers in the same Pod a shared directory backed by the node’s boot disk. Kubernetes creates it empty, keeps its data across container restarts, and removes the data when the Pod is deleted, rescheduled, moved, or the node becomes unhealthy. Use it for temporary data rather than long-term storage. section 9.1.1

Use emptyDir when the data has short-lived operational value:

  • Share files between containers in one Pod. section 9.1.1
  • Preserve an on-disk cache across restarts of an individual container. section 9.1.1
  • Let an init container prepare configuration for a main container without using persistent storage. section 9.2.2
  • Avoid emptyDir for data that must survive Pod rescheduling; use persistent storage instead. section 9.1.1 section 9.2.2

Mounting an emptyDir cache

Define a volume with `emptyDir: {}` and mount it into a container, such as at `/app/cache/`. Multiple containers in the Pod can mount the same named volume. In a Redis StatefulSet, an init container instead copies either a primary or replica configuration from a ConfigMap into an emptyDir mount, which the Redis container then reads. section 9.2.2

How Kubernetes for Developers covers it

How deep it goes
Defines node-backed storage, lifecycle loss, restart persistence, and mounting patterns, but defers scratch-space alternatives.
Examples
Uses a cache mount and Redis configuration copied from a ConfigMap into shared emptyDir storage.
What it assumes
Assumes Pods and containers, while defining volumes as directories accessible to containers.
What you can do after
Apply it by declaring an emptyDir volume and mounting it wherever Pod containers need temporary shared storage.
How it connects
Connects Pods, containers, init containers, ConfigMaps, StatefulSets, and PersistentVolumes.

Also explained in

Compare how 3 books explain emptydir volume →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.