In Kubernetes, each container running in a pod can read and write data to its own isolated file system.

When the container restarted, the file system will be destroyed and the data will be lost.

When running multiple containers together in a Pod, it is necessary to share files between those containers.

The Kubernetes Volume abstraction solves these problems.

A Kubernetes volume is essentially a directory accessible to all containers running in a pod.

We have different types of volumes in Kubernetes and the type defines how the volume is created and its content.

node-local types:

  • emptyDir
  • hostPath
  • local

file-sharing types:

  • nfs
  • efs
  • azureFile

cloud provider-specific types:

  • awsElasticBlockStore
  • azureDisk
  • gcePersistentDisk

distributed file system types:

  • glusterfs
  • cephfs

special-purpose types:

  • secret
  • configmap

To use a volume, a pod specifies what volumes to provide for the pod (the spec.volumes field) and where to mount those into containers(the spec.containers.volumeMounts field).