kubernetes volumes
- files created in a container are ephemeral, i.e. if a kubernetes pod is restarted, the newly created containers will not have access to the files from the previous containers
kubernetes volumes
mitigates the issue of sharing files
Volume types:
emptyDir
: initial empty directoryhostPath
: mounted directory from the cluster node filesystemnfs
: a shared NFSgcePersistentDisk
,awsElasticBlokStore
,azureDisk
: volumes exposed by cloud providerscinder
,cephfs
,iscsi
,flocker
…: network storageConfigMaps
,Secrets
,downwardAPI
: volumes specialized for exposingKubernetes
resourcesPersistentVolumeClaim
: a way to dynamically allocate volumes
EmptyDir
- the lifecycle of an
EmptyDir
volume is linked to the kubernetes pod, i.e. if the kubernetes pod is destroyed, so is the volume - useful for containers in the same kubernetes pod that needs to collaborate together
HostPath
- sometime, a kubernetes pod needs to access to the cluster node filesystem, e.g. a kubernetes pod created by a kubernetes DaemonSet to archive logs
- those volumes are persistent, but it’s not reliable because your kubernetes pod may not be run in the same node
Persistent Volumes and Persistent Volumes Claims
- abstraction layer to provision and consume volumes
PersistentVolume
is a storage space dedicated for cluster adminsPersistentVolumeClaim
is a storage space requested by the cluster usersPVC
are similar to kubernetes pod- kubernetes pods consumes resources (CPU & RAM) of the cluster node
PVC
consumes cluster storage resource
PVC
providesPV
with some criteria:- storage size
- access type (RW, RO, …)
PVC
do not expose the way it provision the storage to the usersStorageClass
are a way to expose different types of available volumes
Lifecycle of PV and PVC
PV
can be provisionedstatically
ordynamically
static PV
are pre-provisioned by the adminsdynamic PV
are provisioned on the fly by the cluster using theStorageClass
- a
PVC
must specify aStorageClass
- an empty
StorageClass
(i.e.""
) is equivalent to astatic PV
- ⚠️ if no
PV
matches the request, it will be on stand-by indefinitely (or until its deletion) - ⚠️ deleting a kubernetes pod does not delete the associated
PVC
- the
ReclaimPolicy
associated to thePV
determine what happens to thePV
once it’s freed:retained
: thePV
is no longer used but can be associated to anotherPVC
recycled
: thePV
is cleaned, i.e. its data are deleted, and once the deletion is finished, thePV
can be associated to aPVC
deleted
: thePV
is deleted
- the
Access modes
ReadWriteOnce
(RWO): the volume can be mounted in RW for a single nodeReadOnlyMany
(ROX): the volume can be mounted in RO for multiple nodesReadWriteMany
(RWX): the volume can be mounted in RW for multiple nodes
PV example
PVC example
PVC
usage: