How to use ephemeral storage?

· Category: Kubernetes

Short answer

Ephemeral storage is temporary storage tied to the Pod lifecycle. The most common type is emptyDir, which creates an empty directory when the Pod starts and deletes it when the Pod terminates.

Steps

  1. Define an emptyDir volume in the Pod spec.
  2. Mount it into the container.
  3. Optionally set storage requests and limits.

Example

apiVersion: v1
kind: Pod
metadata:
  name: temp-worker
spec:
  containers:
  - name: worker
    image: busybox
    volumeMounts:
    - name: scratch
      mountPath: /scratch
    resources:
      requests:
        ephemeral-storage: "1Gi"
      limits:
        ephemeral-storage: "2Gi"
  volumes:
  - name: scratch
    emptyDir: {}

Tips

  • Use emptyDir for caching, temporary processing, and shared scratch space between containers.
  • Use medium: Memory for a RAM-backed tmpfs.
  • Monitor ephemeral storage usage to prevent eviction.

Common issues

  • Exceeding ephemeral storage limits causes Pod eviction.
  • Node disk pressure can trigger mass evictions.
  • emptyDir data is lost on Pod restart.