liveBook · Manning

Emptydir volume

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

An emptyDir volume is a Kubernetes volume type that provides initially empty storage for a pod and is deleted when the pod is deleted.

An emptyDir volume provides temporary storage that starts empty, can be mounted into containers in the same pod, and disappears when the pod is deleted. It suits pod-local data rather than data that must survive pod replacement. section 4.2.2 section 7.4

Use emptyDir when the operational task requires:

  • Sharing transient log data between a main application container and a sidecar container. section 4.2.2
  • Providing temporary application data inside a pod without creating a persistent volume or claim. section 9.3.6
  • Remembering that deleting the pod permanently deletes the volume's contents. section 4.2.2

Mount an emptyDir volume for log collection

Define the volume under spec.volumes and mount the same name in the container: volumes: [{name: logvol, emptyDir: {}}]; volumeMounts: [{mountPath: /var/log, name: logvol}]. Create it with kubectl create -f log-collector.yaml, then verify the pod with kubectl get po and inspect the mount using kubectl describe po log-collector. section 7.4

  1 apiVersion: v1
  2 kind: Pod
  3 metadata:
  4   creationTimestamp: null
  5   labels:
  6     run: log-collector
  7   name: log-collector
  8 spec:
  9   containers:
 10   - command:
 11     - sleep
 12     - "3600"
 13     image: busybox
 14     name: log-collector
 15     resources: {}
 16     volumeMounts:
 17     - mountPath: /var/log
 18       name: logvol
 19   dnsPolicy: ClusterFirst
 20   restartPolicy: Always
 21   volumes:
 22   - name: logvol
 23     emptyDir: {}

Use the complete Pod manifest to check the required volume and volumeMount placement, names, and mount path. section 7.4

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Defines YAML placement, mounts it into a container, verifies EmptyDir with kubectl describe, and contrasts it with persistent storage.
Examples
Uses a BusyBox log-collector mounted at /var/log and a Redis pod with ephemeral data.
What it assumes
Assumes basic Pod manifests and kubectl editing; teaches the emptyDir volume and volumeMount definitions.
What you can do after
Build it from scratch with kubectl and YAML, then verify the pod and mounted volume.
How it connects
Connects Pods, sidecar containers, ConfigMaps, persistent volumes, and volume mounts.

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 Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.