Configure a Pod to Use a PersistentVolume for Storage

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.

  1. One problem is the loss of files when a container crashes.
  2. The second problem occurs when sharing files between containers running together in a Pod.

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

  1. awsElasticBlockStore: An awsElasticBlockStore volume mounts an Amazon Web Services (AWS) EBS volume into your pod.
  2. azureDisk: The azureDisk volume type mounts a Microsoft Azure Data Disk into a pod.
  3. azureFile: The azureFile volume type mounts a Microsoft Azure File volume (SMB 2.1 and 3.0) into a pod.
  4. cephfs: A cephfs volume allows an existing CephFS volume to be mounted into your Pod. 
  5. cinder: The cinder volume type is used to mount the OpenStack Cinder volume into your pod.
  6. configMap: A ConfigMap provides a way to inject configuration data into pods.
  7. fc (fibre channel): An fc volume type allows an existing fibre channel block storage volume to mount in a Pod.
  8. gcePersistentDisk: A gcePersistentDisk volume mounts a Google Compute Engine (GCE) persistent disk (PD) into your Pod.
  9. glusterfs: A glusterfs volume allows a Glusterfs (an open source networked filesystem) volume to be mounted into your Pod.
  10. iscsi: An iscsi volume allows an existing iSCSI (SCSI over IP) volume to be mounted into your Pod. 
  11. local: A local volume 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 hostPath volumes, local volumes are used in a durable and portable manner without manually scheduling pods to nodes.
  12. nfs: An nfs volume allows an existing NFS (Network File System) share to be mounted into a Pod.
  13. persistentVolumeClaim: A persistentVolumeClaim volume is used to mount a PersistentVolume into a Pod.
  14. quobyte: A quobyte volume allows an existing Quobyte volume to be mounted into your Pod.
  15. rbd: An rbd volume allows a Rados Block Device (RBD) volume to mount into your Pod. 
  16. secret:  secret volume 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. 
  17. storageOS: A storageos volume allows an existing StorageOS volume to mount into your Pod.
  18. vsphereVolume: A vsphereVolume is used to mount a vSphere VMDK volume into your Pod.
  19. hostPath: A hostPath volume 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.

Using subPath

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
  name: my-lamp-site
    - name: mysql
      image: mysql
        value: "rootpasswd"
      - mountPath: /var/lib/mysql
        name: site-data
        subPath: mysql
    - name: php
      image: php:7.0-apache
      - mountPath: /var/www/html
        name: site-data
        subPath: html
    - name: site-data
        claimName: my-lamp-site-data

Volume PluginReadWriteOnceReadOnlyManyReadWriteMany
CSIdepends on the driverdepends on the driverdepends on the driver
FlexVolumedepends on the driver
VsphereVolume– (works when Pods are collocated)

Leave a Reply

Your email address will not be published.