This page provides an overview of Volumes in Kubernetes, and their use with Kubernetes Engine.


On-disk files in a container are the simplest place for an application to write data, but this approach has drawbacks. The files are lost when the container crashes or stops for any other reason. Furthermore, files within a container are inaccessible to other containers running in the same Pod. The Kubernetes Volume abstraction addresses both of these issues.

Conceptually, a volume is a directory which is accessible to all of the containers in a Pod. The volume source declared in the Pod specification determines how the directory is created, the storage medium used, and the directory's initial contents. A Pod specifies what Volumes it contains and the path where containers mount the Volume.

Ephemeral Volume types have the same lifetimes as their enclosing Pods. These Volumes are created when the Pod is created, and they persist through container restarts. When the Pod terminates or is deleted its Volumes go with it.

Other Volume types are interfaces to durable storage that exist independently of a Pod. Unlike ephemeral volumes, data in a Volume backed by durable storage is preserved when the Pod is removed. The volume is merely unmounted and the data can be handed off to another Pod. You should use PersistentVolume resources to manage the lifecycle of durable storage types, rather than directly specifying them.

Types of volumes

Volumes differ in their storage implementation and their initial contents. You can choose the Volume source that best fits your use case. Several common Volume sources are described below:

An ephemeral volume type that provides an empty directory that containers in the Pod can read and write from. When the Pod is removed from a node for any reason, the data in the emptyDir is deleted forever. emptyDirs are useful for scratch space and sharing data between multiple containers in a Pod.
Used to make configuration data accessible to applications. The files in a configMap Volume are specified by a ConfigMap resource.
Used to make sensitive data, such as passwords, OAuth tokens, and SSH keys, available to applications.
Used to make Downward API data available to applications. This data includes information about the Pod and container in which an application is running in. For example, a Pod can be configured to expose a DownwardAPIVolumeFile to applications that includes the Pod's namespace and IP address.
Cluster operators can provision durable storage to be used by applications. A Pod uses a PersistentVolumeClaim to mount a Volume that is backed by this durable storage.

For a complete list of Volume types, refer to the Kubernetes Volumes documentation.

Using Volumes

You can create a Deployment of Pod where each Pod contains one or more Volumes. The following Deployment manifest describes a Deployment of three Pods that each have an emptyDir Volume.

In this example:

  • The metadata: name field specifies a Deployment named volumes-example-deployment.
  • The Pod template specification includes a volumes field that describes an emptyDir volume named cache-volume.
  • The container specification includes a volumeMounts: field that specifies that the Volume named cache-volume is mounted at the file path /cache.


apiVersion: apps/v1beta2
kind: Deployment
  name: volumes-example-deployment
  replicas: 3
      app: demo
        app: demo
      - name: test-container
        image: gcr.io/google-samples/hello-app:1.0
        - mountPath: /cache
          name: cache-volume
        - name: cache-volume
          emptyDir: {}

To create a Deployment from this manifest file, run the following command:

kubectl apply -f volumes-demo.yaml

Verify that your Deployment is running correctly and has the expected Volume with this command:

kubectl describe pods volumes-example-deployment

This prints information about each of the three Pods in the Deployment. The output shows that each Pod has a container, test-container, with the /cache mount:

  /cache from cache-volume (rw)

The output also slows that each Pod contains a Volume named cache-volume:

    Type:    EmptyDir (a temporary directory that shares a pod's lifetime)

For more information about creating Deployments, refer to Creating a Deployment.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Kubernetes Engine