#
Volumes in Kubernetes
This tutorial explains what the volumes are in Kubernetes.
A Volume in Kubernetes represents a directory with data that is accessible across multiple containers in a Pod. Volumes provide a plug-in mechanism to connect ephemeral containers with persistent data stores elsewhere.
Types of Kubernetes Volumes:
- Ephemeral Volumes: lives as long as the pod lives
emptyDir
: empty at Pod startup and uses the node storage or the RAM. Once the Pod is removed from the node, the data in the emptyDir is erased. This type of volume is suitable for temporary data storage.configMap
: a mount directory which keeps the configMap datadownwardAPI
: mount the information about the pod into the container as a special volumesecret
: the same as for configMap volumes, but the data is not in clear text.generic ephemeral volumes
: which can be provided by all storage drivers that also support persistent volumes
Info
- When we mount a configMap volume, each key-value pair is protected into the container's filesystem as a file. The name of the file is the key and the content is the value.
- If configMap is not accessible as a volume, the key-value pairs are injected in the container's environment variables.
Durable Volumes : when pods and volumes lifecycles are independent
hostPath
: mounts a file or directory from the host node’s filesystem into your pod.PersistentVolume (PV)
: is a Kubernetes resource that is created by an administrator or dynamically using Storage Classes independently of the Pod.PersistentVolumeClaim (PVC)
: claims the space to be referenced in a pod. A PersistentVolumeClaim is created by specifying the minimum size and the access mode they require from the PersistentVolume. A PVC is a storage request made by a user. If the storage is not available (ex. you have 2 PV of 50Gb each, and you have a PVC of 70Gb) the pod will not be able to use that storage claimed using a PVC.gcePersistentDisk
: mounts a Google Cloud Persistent Disk into your Pod.awsElasticBlockStore
: mounts an Amazon Web Services (AWS) Elastic Block Store into your Pod.azureDiskVolume
: mounts a Microsoft Azure Data Disk into a Pod.gitRepo
: mounts an empty directory and clones a git repository into it for your pod to use.
Info
- HostPath volumes pose many security risks. Avoid using these possible whenever possible.
Using PersistentVolume (PV) you will take the whole volume, using PersistentVolumeClaim (PVC) you will take only a part of the PV.