Course contentsShow
← Cloud and Infrastructure
Lesson 1151 of 2,98923. Kubernetes WorkloadsFree lesson

Pod Storage and Volumes Basics

Attaching volumes to Pods for ephemeral and shared storage between containers.

Pod Storage and Volumes Basics

You'll learn how to attach storage volumes to Pods so containers can persist data and share files with each other.

The Problem with Container Storage

By default, containers use ephemeral storage—files written inside a container disappear when that container stops or restarts. This is fine for temporary data, but what if you need to save logs, share configuration files between containers, or persist a database?

What Are Volumes?

A volume in Kubernetes is a directory accessible to all containers in a Pod. Think of it like a shared USB drive plugged into your Pod—all containers can read from and write to it.

Volumes solve two key problems:

  • Data persistence: Data survives container restarts
  • Data sharing: Multiple containers in the same Pod can access the same files

Common Volume Types

Kubernetes supports many volume types, starting with the simplest:

  • emptyDir: Creates an empty directory when the Pod starts. Perfect for temporary scratch space or sharing data between containers. Data is lost when the Pod is deleted.
  • hostPath: Mounts a directory from the worker node's filesystem. Useful for accessing node-level resources (use cautiously—creates node dependency).

How Volumes Work

Volumes are defined in the Pod specification under spec.volumes, then mounted into specific containers using volumeMounts. Each container decides where to mount the shared volume in its own filesystem.

Think of it like setting up a shared folder: first you create the folder (define the volume), then you tell each person where to access it on their computer (mount it in each container).

Key Takeaway: Volumes let you attach storage to Pods for ephemeral scratch space or container-to-container file sharing, with the lifetime and type depending on which volume type you choose.