Creating a Persistent Volume Claim

Container storage via a container's root file system is ephemeral, and can disappear upon container deletion and creation. To provide a durable location to store data and prevent it from being lost, you can create and use persistent volumes to store data outside of containers.

You can define and apply a persistent volume claim to your cluster, which in turn creates a persistent volume that's bound to the claim. A claim is a block storage volume in the underlying IaaS provider that's durable and offers persistent storage, enabling your data to remain intact, regardless of whether the containers that the storage is connected to are terminated.

With Oracle Cloud Infrastructure as the underlying IaaS provider, you can provision persistent volume claims by attaching volumes from the Block Storage service.

A persistent volume claim (PVC) is a request for storage, similar to how a pod requests compute resources. A PVC provides an abstraction layer to underlying storage. For example, an administrator could create a number of static persistent volumes (PVs) that can later be bound to one or more persistent volume claims. This is analogous to an administrator creating cluster nodes to which pods are later assigned. If none of the static persistent volumes match the user's PVC request, the cluster may attempt to dynamically create a PV that matches the PVC request. This example uses the latter approach, and it assumes that the cluster administrator has not created any suitable PVs that match the PVC request—meaning that the PVCs will dynamically create the PVs for this example.

The minimum amount of persistent storage that a PVC can request is 50 gigabytes. If the request is for less than 50 gigabytes, the request is rounded up to 50 gigabytes.

The following YAML defines two PVCs that each request 50 gigabytes of persistent storage (storage: 50Gi). You use names of the PVCs (for example, mysqlclaim) when defining which claims to use as the volumes of a deployment.

In the previous example, the PVCs request storage in availability domains in the Ashburn region using matchLabels:failure-domain.beta.kubernetes.io/zone. Note that when you specify values for matchLabels:failure-domain.beta.kubernetes.io/zone, you must use the shortened versions of availability domain names. For example US-ASHBURN-AD-1, US-ASHBURN-AD-2. See Availability by Region Name and Region Code for a list of shortened versions of availability domain names.

You can use these persistent volumes when creating other objects, such as deployments. For example, the following deployment definition instructs the system to use the mysqlclaim PVC as the mysql-persistent-storage volume, which is mounted by pods hosting the deployment as /var/lib/mysql.