Chapter 33 of 47 · Storage, part 4

Ephemeral volumes

Sometimes a Pod needs real storage (a big disk, a fast SSD, secrets fetched from Vault) but only for as long as the Pod lives. Making a PVC by hand and remembering to delete it is clumsy. Ephemeral volumes are created with the Pod and cleaned up with it, automatically.

The ephemeral family

You have already met most of it. "Ephemeral" just means: this volume lives exactly as long as its Pod.

TypeWhat it gives youChapter
emptyDirAn empty folder on the node's disk or in RAM30
configMap, secret, downwardAPIFiles from Kubernetes data (downwardAPI: the Pod's own name, labels, limits)18, 19
generic ephemeralA real disk from a StorageClass, for one Pod's lifetimethis one
CSI ephemeral inlineA volume a CSI driver builds specially for the Pod, e.g. secrets from Vaultthis one

Generic ephemeral volumes

Think "emptyDir, but on a proper disk from a StorageClass": any size, SSD, encrypted, not limited by the node's spare space. You write a PVC template inside the Pod:

apiVersion: v1
kind: Pod
metadata:
  name: report-builder
spec:
  containers:
    - name: builder
      image: report-builder:1.0
      volumeMounts:
        - name: scratch
          mountPath: /scratch
  volumes:
    - name: scratch
      ephemeral:
        volumeClaimTemplate:
          spec:
            accessModes: [ReadWriteOnce]
            storageClassName: fast-ssd
            resources:
              requests:
                storage: 100Gi

ephemeral.volumeClaimTemplate

Kubernetes creates a PVC for this Pod automatically, named <pod>-<volume>: here report-builder-scratch. The Pod owns it, so when the Pod is deleted the PVC is deleted too (and with reclaim Delete, the disk).

  1. $ kubectl apply -f report-builder.yaml
    $ kubectl get pvc
    NAME                     STATUS   CAPACITY   STORAGECLASS
    report-builder-scratch   Bound    100Gi      fast-ssd

    The PVC and a fresh 100Gi disk appear together with the Pod.

  2. builder: crunching 80Gi of data in /scratch …
    builder: report.pdf uploaded to S3

    The job uses it like any disk, and it survives container restarts within the Pod.

  3. $ kubectl delete pod report-builder
    $ kubectl get pvc
    No resources found in default namespace.

    Pod gone → its PVC and disk are gone. Nothing to clean up, nothing left costing money.

Good for: big temporary work (video transcoding, data processing, builds) that would overflow the node's disk with an emptyDir.

CSI ephemeral inline volumes

Here a CSI driver (a storage plugin) builds the volume's content for this one Pod, described right in the Pod spec. No PVC, no StorageClass. The best-known example is the Secrets Store CSI Driver: it fetches secrets from AWS Secrets Manager, Azure Key Vault, Google Secret Manager or HashiCorp Vault and mounts them as files, so they never need to exist as Kubernetes Secrets at all.

spec:
  containers:
    - name: posts
      image: micro-posts:1.0
      volumeMounts:
        - name: secrets
          mountPath: /mnt/secrets
          readOnly: true
  volumes:
    - name: secrets
      csi:
        driver: secrets-store.csi.k8s.io
        readOnly: true
        volumeAttributes:
          secretProviderClass: posts-aws-secrets   # which secrets to fetch, defined separately
$ kubectl exec deployment/posts-depl -- cat /mnt/secrets/DB_PASSWORD
hunter2

Side by side

emptyDirGeneric ephemeralCSI inlinePVC (persistent)
Lives as long asThe PodThe PodThe PodUntil you delete the PVC
Backed byNode disk or RAMA StorageClass diskA CSI driverA PV
SizeWhat the node has freeAnything you requestDriver-specificAnything you request
Creates a PVCNoYes, automaticallyNoYou create it
Typical useCache, sharing between containersBig temporary workSecrets from an external vaultData that must survive

Which storage should I use?

Answer the questions for your use case:

Recap

Ephemeral volumes: common questions

What is a generic ephemeral volume?

A volume defined with a PVC template inside the Pod. Kubernetes creates the PVC with the Pod and deletes it with the Pod, giving real disk storage for the Pod lifetime.