This document shows you how to create Volume resources in your Google Kubernetes Engine (GKE) cluster.

You manage how your containerized applications store and share data in a Kubernetes cluster by creating Kubernetes Volumes and configuring them within your Deployments. By creating Kubernetes Volumes, you can deploy stateful microservices. This also increases development velocity as you manage application data consistently.

This document is for developers and administrators who manage GKE container storage. To learn more about common roles and example tasks that we reference in Google Cloud content, see [Common GKE user roles and tasks](https://docs.cloud.google.com/kubernetes-engine/enterprise/docs/concepts/roles-tasks.md.txt).

## Using Volumes with Deployments

You can [create a Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
of Pods where each Pod contains one or more
Volumes. The following Deployment manifest describes a Deployment of three Pods
that each have an [emptyDir Volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir). For more information, see [Creating a Deployment](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/stateless-apps.md.txt#create).

In this example:

- The `metadata: name` field specifies a Deployment named `volumes-example-deployment`.
- The [Pod template](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/#pod-templates) 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 path `/cache`.
- The manifest file is named `volumes-demo.yaml`.

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
 name: volumes-example-deployment
spec:
 replicas: 3
 selector:
  matchLabels:
   app: demo
 template:
  metadata:
   labels:
    app: demo
  spec:
   containers:
   - name: test-container
    image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
    volumeMounts:
    - mountPath: /cache
     name: cache-volume
   volumes:
    - name: cache-volume
     emptyDir: {}
```

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

```bash
kubectl apply -f volumes-demo.yaml
```

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

```bash
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:

    Mounts:
      /cache from cache-volume (rw)

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

    Volumes:
      cache-volume:
        Type:    EmptyDir (a temporary directory that shares a pod's lifetime)

## What's next

- [Learn about PersistentVolumes, PersistentVolumeClaims, and dynamic storage provisioning](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes.md.txt).
- [Learn about using the Compute Engine persistent disk CSI Driver](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/gce-pd-csi-driver.md.txt).