Why we need Kubernetes Volumes?
On-disk files in a container are ephemeral, which presents some problems for non-trivial applications when running in containers.
- One problem is the loss of files when a container crashes.
- The second problem occurs when sharing files between containers running together in a
The Kubernetes volume abstraction solves both of these problems.
Docker has a concept of volumes, though it is somewhat looser and less managed. A Docker volume is a directory on a disk or in another container. Docker provides volume drivers, but the functionality is somewhat limited.
Type of Volumes
- awsElasticBlockStore: An
awsElasticBlockStorevolume mounts an Amazon Web Services (AWS) EBS volume into your pod.
- azureDisk: The
azureDiskvolume type mounts a Microsoft Azure Data Disk into a pod.
- azureFile: The
azureFilevolume type mounts a Microsoft Azure File volume (SMB 2.1 and 3.0) into a pod.
- cephfs: A
cephfsvolume allows an existing CephFS volume to be mounted into your Pod.
- cinder: The
cindervolume type is used to mount the OpenStack Cinder volume into your pod.
- configMap: A ConfigMap provides a way to inject configuration data into pods.
- fc (fibre channel): An
fcvolume type allows an existing fibre channel block storage volume to mount in a Pod.
- gcePersistentDisk: A
gcePersistentDiskvolume mounts a Google Compute Engine (GCE) persistent disk (PD) into your Pod.
- glusterfs: A
glusterfsvolume allows a Glusterfs (an open source networked filesystem) volume to be mounted into your Pod.
- iscsi: An
iscsivolume allows an existing iSCSI (SCSI over IP) volume to be mounted into your Pod.
- local: A
localvolume represents a mounted local storage device such as a disk, partition or directory. Local volumes can only be used as a statically created PersistentVolume. Dynamic provisioning is not supported. Compared to
localvolumes are used in a durable and portable manner without manually scheduling pods to nodes.
- nfs: An
nfsvolume allows an existing NFS (Network File System) share to be mounted into a Pod.
- persistentVolumeClaim: A
persistentVolumeClaimvolume is used to mount a PersistentVolume into a Pod.
- quobyte: A
quobytevolume allows an existing Quobyte volume to be mounted into your Pod.
- rbd: An
rbdvolume allows a Rados Block Device (RBD) volume to mount into your Pod.
secretvolume is used to pass sensitive information, such as passwords, to Pods. You can store secrets in the Kubernetes API and mount them as files for use by pods without coupling to Kubernetes directly.
- storageOS: A
storageosvolume allows an existing StorageOS volume to mount into your Pod.
- vsphereVolume: A
vsphereVolumeis used to mount a vSphere VMDK volume into your Pod.
- hostPath: A
hostPathvolume mounts a file or directory from the host node’s filesystem into your Pod. This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.
Sometimes, it is useful to share one volume for multiple uses in a single pod. The
volumeMounts.subPath property specifies a sub-path inside the referenced volume instead of its root.
The following example shows how to configure a Pod with a LAMP stack (Linux Apache MySQL PHP) using a single, shared volume. This sample
subPath configuration is not recommended for production use.
The PHP application’s code and assets map to the volume’s
html folder and the MySQL database is stored in the volume’s
mysql folder. For example:
apiVersion: v1 kind: Pod metadata: name: my-lamp-site spec: containers: - name: mysql image: mysql env: - name: MYSQL_ROOT_PASSWORD value: "rootpasswd" volumeMounts: - mountPath: /var/lib/mysql name: site-data subPath: mysql - name: php image: php:7.0-apache volumeMounts: - mountPath: /var/www/html name: site-data subPath: html volumes: - name: site-data persistentVolumeClaim: claimName: my-lamp-site-data
|CSI||depends on the driver||depends on the driver||depends on the driver|
|FlexVolume||✓||✓||depends on the driver|
|VsphereVolume||✓||–||– (works when Pods are collocated)|