A PV (Persistent Volume) in Kubernetes is a resource used to store data. It is attached to pods but have a separate lifecycle, specified by its Reclaim Policy. This policy determines if a PV will continue to exist or will be deleted when a pod attached to it gets destroyed.
A PV represents a piece of available storage. To use a PV, a user needs to create a persistent volume claim (PVC), which is a request for storage. Kubernetes passes this request to a storage class, which creates PVs automatically in response to the PVC.
There are four storage classes based on the disk type: standard, ultra, cold, and ssd_hiiops. The standard disk-type storage class exists by default, so you simply need to create a default PVC. For any other disk type, you first have to create a storage class with the required disk type and then create a PVC.
1. Create a YAML file to configure a PVC:
Enter your custom values instead:
2. Run the kubectl command from the file directory:
kubectl apply -f <name of the YAML file>.yaml
You will get the output:
persistentvolumeclaim/<the name of the created PVC> created
It means you have created a PVC with a standard disk-type storage class. To connect the PVC to your pods, refer to the Bind a PVC to a pod section.
You can check the available disk types in different regions in the Gcore Control panel or via an API request.
1. Create a YAML file to configure a storage class with the required disk type:
Enter your custom values instead:
2. Run the kubectl command from the file directory:
kubectl apply -f <name of the created YAML file>.yaml
You will get the output:
storageclass/<the name of the created storage class> created
3. Create a YAML file to configure a PVC:
Enter your custom values instead:
4. Run the kubectl command from the file directory:
kubectl apply -f <name of the created YAML file>.yaml
You will get the output:
persistentvolumeclaim/<the name of the created PVC> created
It means you have created a PVC with a storage class of the required disk type. To connect the PVC to your pods, refer to the section below.
1. Create a YAML file to bind the created storage class to your pod.
Enter your custom values instead:
2. Run the kubectl command from the file directory:
kubectl apply -f <name of the created YAML file>.yaml
3. You will get the output:
pod/<the pod name> created
It means you have connected the PVC to your pod, and now its containers can access the storage.
Was this article helpful?
Discover our offerings, including virtual instances starting from 3.7 euro/mo, bare metal servers, AI Infrastructure, load balancers, Managed Kubernetes, Function as a Service, and Centralized Logging solutions.