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 Cloud de Confiance by S3NS content, see Common GKE user roles and tasks.
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. For more information, see Creating a Deployment.
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 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)