Understanding Volumes in Kubernetes
Volumes in Kubernetes provide a way for containers to persist and share data. Unlike a container's filesystem, data in volumes is preserved across container restarts.
Common Volume Types:
emptyDir
– temporary storage, erased when the pod is deletedhostPath
– mounts a file or directory from the host nodeconfigMap
&secret
– inject configuration or secret datapersistentVolumeClaim
– binds to persistent storage
Example:
volumes:
- name: cache-volume
emptyDir: {}
containers:
- name: app
image: myapp
volumeMounts:
- mountPath: /cache
name: cache-volume
Volumes help ensure that application data can survive container crashes and can also be shared between containers in a pod.