Kubernetes supports a variety of persistent volumes, for example, public cloud storage such as AWS EBS and Google persistent disks. It also supports network (distributed) filesystems such as NFS, GlusterFS, and Ceph. In addition, it can also support a block device such as iSCSI and Fibre Channel. Based on the environment and infrastructure, a Kubernetes administrator can choose the best matching types of persistent volume.
The following example is using a GCP persistent disk as a persistent volume. The first step is to create a GCP persistent disk and name it gce-pd-1.
Then, specify the name gce-pd-1 in the Deployment definition:
$ cat tomcat-pv.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
spec:
replicas: 1
selector:
matchLabels:
run: tomcat
template:
metadata:
labels:
run: tomcat
spec:
containers:
- image: tomcat
name: tomcat
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /usr/local/tomcat/logs
name: tomcat-log
volumes:
- name: tomcat-log
gcePersistentDisk:
pdName: gce-pd-1
fsType: ext4
This will mount the persistent disk from the GCE persistent disk to /usr/local/tomcat/logs, which can persist Tomcat application logs.