Volume Types
Kubernetes supports many different volume types, each suited for different use cases. Understanding volume types helps you choose the right storage solution for your application. Think of volume types as different ways to connect storage to your containers—some are temporary like sticky notes, while others are permanent like filing cabinets.
Volume Categories
Volumes in Kubernetes fall into two main categories:
Ephemeral Volumes
Ephemeral volumes have a lifecycle tied to the pod. When the pod is deleted, the data in ephemeral volumes is lost. These are useful for temporary data, caching, or sharing data between containers in the same pod.
Persistent Volumes
Persistent volumes survive pod deletions and can be used across pod restarts. The data persists independently of the pod lifecycle, making them essential for databases, file storage, and any application that needs to retain data.
Common Ephemeral Volume Types
emptyDir
A temporary directory that shares a pod’s lifetime. Perfect for temporary files, caching, or scratch space.
configMap
Makes ConfigMap data available as files in a directory. Read-only, useful for configuration files.
secret
Makes Secret data available as files in a directory. Read-only, useful for sensitive configuration like certificates and API keys.
downwardAPI
Exposes pod and container field values as files. Useful when containers need metadata about themselves.
Common Persistent Volume Types
CSI (Container Storage Interface)
The modern standard for persistent volumes. CSI drivers allow Kubernetes to use any storage system that provides a CSI driver, including cloud storage (AWS EBS, GCE Persistent Disk, Azure Disk) and on-premises storage.
NFS
Network File System volumes that can be shared across multiple pods. Supports ReadWriteMany access mode.
iSCSI
Internet Small Computer Systems Interface volumes for connecting to block storage devices over a network.
Local
Direct connection to local storage on a node. Requires careful node selection and doesn’t support automatic migration.
Volume Lifecycle Comparison
ephemeral
persistent
When to Use Each Type
Use Ephemeral Volumes When:
- Storing temporary or cache data
- Sharing data between containers in the same pod
- Providing configuration files or secrets to containers
- The data doesn’t need to survive pod restarts
Use Persistent Volumes When:
- Storing database data
- Persisting application state
- Storing user uploads or generated files
- The data must survive pod restarts, updates, or node failures
- Multiple pods need to share the same data (with appropriate access modes)
Example: Ephemeral vs Persistent
Here’s a comparison showing both volume types in action:
Ephemeral Volume (emptyDir):
apiVersion: v1
kind: Pod
metadata:
name: app-with-cache
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: cache
mountPath: /tmp/cache
volumes:
- name: cache
emptyDir: {} # Ephemeral - lost when pod deleted
Persistent Volume (PVC):
apiVersion: v1
kind: Pod
metadata:
name: app-with-data
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: data
mountPath: /var/www/html
volumes:
- name: data
persistentVolumeClaim:
claimName: my-data-pvc # Persistent - survives pod deletion
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-data-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Best Practices
- Choose ephemeral for temporary data - Use emptyDir, configMap, or secret for data that doesn’t need persistence
- Use persistent volumes for important data - Always use PVs/PVCs for databases, user data, or any data that must survive restarts
- Consider access patterns - Match volume types to your access requirements (single pod vs multiple pods)
- Use CSI for flexibility - Prefer CSI volumes over in-tree volume types for better compatibility
- Test volume behavior - Understand how volumes behave when pods restart or are deleted
Topics
- Ephemeral Volumes - Temporary volumes that share pod lifecycle
- CSI Persistent Volumes - Modern persistent storage interface
- Block vs Filesystem - Raw block devices vs mounted filesystems
See Also
- PVs & PVCs - How to request and use persistent storage
- StorageClasses - Dynamic provisioning of persistent volumes
- StatefulSets - Managing stateful applications with persistent storage