This page explains how to create Volume resources in your cluster. For more details, see the Kubernetes documentation about Volumes .
Using Volumes with Deployments
You can create a 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 .
In this example:
- The
metadata: namefield specifies a Deployment namedvolumes-example-deployment. - The Pod template
specification includes a
volumesfield that describes an emptyDir volume namedcache-volume. - The container specification includes a
volumeMounts:field that specifies that the Volume namedcache-volumeis mounted at the file path/cache. - The manifest file is named
volumes-demo.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:
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:
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)
For more information about creating Deployments, refer to Creating a Deployment .

