Definition

Kubernetes volume

What is a Kubernetes volume?

A Kubernetes volume is a directory containing data accessible to containers in a given pod, the smallest deployable unit in a Kubernetes cluster. Within the Kubernetes container orchestration and management platform, volumes provide a plugin mechanism that connects ephemeral containers with persistent data storage.

A Kubernetes volume persists until its associated pod is deleted. When a pod with a unique identification is deleted, the volume associated with it is destroyed. If a pod is deleted but replaced with an identical pod, a new and identical volume is also created.

What is a Kubernetes volume used for?

In Kubernetes, a node is a logical grouping of IT resources used to run container workloads. Kubernetes mounts the volumes associated with a given pod to the node that pod is running on. Volumes enable containers to move across infrastructure without losing access to the externally hosted data that they require for the workload.

A pod specifies which volumes it will access and where to place the volumes in its containers. The data within a volume outlasts the containers running in the pod, which can shut down and restart as ephemeral units. Because a container crash is not enough to cut off a pod from a node, data remains safe in volumes even if a container crashes.

Diagram of an example Kubernetes storage architecture, consisting of a Kubernetes controller, persistent volumes and pods.
Although container instances themselves are ephemeral, container orchestrators like Kubernetes offer ways to implement persistent storage for stateful applications.

Volumes cannot be added to other volumes, and links do not exist between volumes. Kubernetes users must specify volume mounting for each container in a pod. A representation of each pod's desired state, including its volumes, is stored in Kubernetes' API server and central controller.

Kubernetes also reconciles deployments using kubelet, an agent that runs on each node in a cluster. For example, kubelet can detect whether a volume cannot be used twice and report that it cannot safely use the volume. It then retries and reevaluates deployment options using the Kubernetes scheduler until it finds one that meets the requirements.

Types of Kubernetes volumes

Kubernetes supports many types of volumes:

  • EmptyDir. A common type of volume created when a pod is first assigned to a node that allows users to mount multiple paths in each container. The volume is initially empty, with all containers in the pod able to read from it.
  • HostPath. Another common type of volume that mounts a directory from the host node's file system into a pod.
  • Local volumes. These represent mounted local storage devices such as partitions, directories or disks.
  • Specialty volumes. These are used to mount platform-specific volumes into a pod. Examples include AzureFileVolume and AzureDiskVolume for Microsoft Azure and VsphereVolume for VMware vSphere.

In some situations, it is helpful to share one volume across multiple uses in a single pod. The Kubernetes property volumeMounts.subPath lets users specify a subpath inside the referenced volume.

This was last updated in March 2023

Continue Reading About Kubernetes volume

Dig Deeper on Containers and virtualization

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close