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 deleted
  • hostPath – mounts a file or directory from the host node
  • configMap & secret – inject configuration or secret data
  • persistentVolumeClaim – 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.

← PrevNext →