Persistent volumes in a Managed Kubernetes cluster
Cloud platform network volume-based persistent volume connectivity is not available in Managed Kubernetes clusters on dedicated servers.
A Persistent Volume is used for long-term data storage in a Managed Kubernetes cluster. To manage persistent volumes in Kubernetes, PersistentVolume (PV), PersistentVolumeClaim (PVC), and StorageClass objects are used. For more information on PV and PVC objects, see the Persistent Volumes section of the Kubernetes documentation, and for the StorageClass object, see the StorageClass instruction.
For persistent volumes in Managed Kubernetes, we recommend using network volumes from the Servercore cloud platform. You can create a persistent volume on a local disk, but the data will be deleted when the node is deleted.
After creating a persistent volume, you can increase or delete it.
You can view all persistent volumes in the Control panel: in the top menu, click Products and select Cloud Servers → the Volumes section.
Create a persistent volume
Creating a persistent volume via the Topology-Aware Volume Provisioning mechanism is not available.
- Create a StorageClass or use an existing StorageClass.
- Create a PersistentVolumeClaim.
- Create a pod with a persistent volume.
1. Create a StorageClass
You can create a StorageClass tied to a single pool segment or to multiple segments of the same pool simultaneously.
When creating a cluster, one StorageClass with a fast network volume is automatically created for all pool segments where the cluster node group is located.
-
Create a YAML file with a manifest for the StorageClass object.
Example of a StorageClass manifest for a single pool segment
kind: StorageClassapiVersion: storage.k8s.io/v1metadata:name: fast-ru-1provisioner: cinder.csi.openstack.orgparameters:type: fast.ru-1afsType: ext4allowVolumeExpansion: trueHere,
fast.ru-1ais the StorageClass type.Example of a StorageClass manifest for multiple segments of the same pool
apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:name: fast-ru-1provisioner: cinder.csi.openstack.orgparameters:type: fast.ru-1volumeBindingMode: WaitForFirstConsumerallowedTopologies:- matchLabelExpressions:- key: topology.cinder.csi.openstack.org/zonevalues: ["ru-1a","ru-1b","ru-1c"]Where:
fast.ru-1is the StorageClass type;"ru-1a","ru-1b","ru-1c"are the pool segments in which a persistent volume can be created with this StorageClass.
-
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest to create a new StorageClass. For example,storage-class.yaml. -
Ensure the StorageClass object is created:
kubectl get scA list of created StorageClass objects will appear in the response. For example:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGEfast-ru-1 cinder.csi.openstack.org Delete Immediate true 16m
StorageClass type
The format of the StorageClass type is <volume_type>.<location>, where volume_type is the network volume type of the cloud platform, and <location> is the pool or pool segment where the network volume will be created.
Disk types correspond to the network volumes of the Servercore cloud platform:
For example, to create a fast volume in the ru-1a pool segment, you must add the following to the StorageClass description:
parameters:
type: fast.ru-1a
2. Create a PersistentVolumeClaim
Volumes can only be used in ReadWriteOnce mode — one volume can only be mounted to one node, and only one pod can be connected to a persistent volume. If multiple pods are connected to the same PV, data may be corrupted. To work with the ReadWriteMany mode (mounting a volume to multiple nodes), you can connect file storage to the cluster nodes.
-
Create a YAML file with a manifest for a PersistentVolumeClaim (PVC) object.
Example manifest:
apiVersion: v1kind: PersistentVolumeClaimmetadata:name: my-pv-claimspec:storageClassName: fast-ru-1accessModes:- ReadWriteOnceresources:requests:storage: 10GiThe pool in the PVC manifest must match the pool of the node to which this PVC is intended to be connected. If you use multiple pools for cluster nodes and PVCs, specify their pool affinity in the Pod object descriptions.
-
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest to create a new PersistentVolumeClaim. For example,pvc.yaml.
3. Create a pod with a persistent volume
If you create a pod (Pod) with a persistent volume, the volume is preserved when the pod is deleted.
-
Create a YAML file with a manifest to create a new pod with a persistent volume.
Example manifest:
apiVersion: v1kind: Podmetadata:name: nginxlabels:app: webservicespec:containers:- name: nginximage: library/nginx:1.17-alpineports:- containerPort: 80volumeMounts:- mountPath: "/var/www/html"name: datavolumes:- name: datapersistentVolumeClaim:claimName: my-pv-claimWhen creating a pod with the
securityContext.fsGroupparameter, the persistent volume will not be mounted with the corresponding GID. To resolve this issue, addfsType: ext4to the StorageClass parameters. -
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest to create a new pod with a persistent volume. For example,pod-with-pv.yaml. -
Check that the PersistentVolume is created:
kubectl get pvA list of PersistentVolumes will appear in the response. For example:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpvc-f171f94c-0d38-41be-947e-2f5d7e46a6c3 10Gi RWO Delete Bound default/my-pv-claim fast-ru-1 97s
Increase a persistent volume
- Check the amount of occupied space in the PersistentVolumeClaim.
- Ensure there are sufficient quotas to increase the PersistentVolume.
- Allow volume expansion in the StorageClass settings.
- Delete pods with the volume that needs to be increased.
- Modify the PersistentVolumeClaim manifest.
1. Check the amount of occupied space in the PVC
Find out the amount of occupied space in the PVC:
kubectl -n <namespace> exec <pod_name> -- df -ah
Specify:
<namespace>— the namespace where the PVC is located;<pod_name>— the name of the pod using the PVC.
2. Check quotas
To determine if there are sufficient resources to increase the persistent volume, check your quotas and, if necessary, change them.
3. Allow persistent volume expansion
In the StorageClass object parameters, specify allowVolumeExpansion: true.
Example manifest:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: example-vol-default
provisioner: vendor-name.example/magicstorage
parameters:
resturl: "http://192.168.10.100:8080"
restuser: ""
secretNamespace: ""
secretName: ""
allowVolumeExpansion: true
reclaimPolicy: Delete
4. Delete pods with the volume that needs to be increased
-
Check which pods are using the PVC:
kubectl describe pvc <pvc_name>Specify
<pvc_name>— the name of the PersistentVolumeClaim. -
Delete the pods that are using the PVC:
kubectl delete pod <pod_name>Specify
<pod_name>— the pod name.
5. Modify the PersistentVolumeClaim manifest
-
Open the YAML file with the PersistentVolumeClaim manifest and modify the
storage:parameter:apiVersion: v1kind: PersistentVolumeClaimmetadata:name: my-pv-claimspec:storageClassName: fast-ru-1accessModes:- ReadWriteOnceresources:requests:storage: 10Gi -
Apply the manifest:
kubectl apply -f <pvc_name>Specify
<pvc_name>— the name of the PersistentVolumeClaim. -
Run the pod using this PVC.
Example manifest:
apiVersion: v1kind: Podmetadata:name: nginxlabels:app: webservicespec:containers:- name: nginximage: library/nginx:1.17-alpineports:- containerPort: 80volumeMounts:- mountPath: "/var/www/html"name: datavolumes:- name: datapersistentVolumeClaim:claimName: my-pv-claim -
Ensure the PersistentVolumeClaim is created:
kubectl get pvc
Delete a persistent volume
If you no longer need a persistent volume, delete the PersistentVolumeClaim that was used to create that volume.
The PV will be deleted immediately if the persistentVolumeReclaimPolicy: Delete parameter is specified in the PVC manifest. For more information on reclaim policy (Reclaim policy), see the Reclaiming section of the Kubernetes documentation.
-
Check which pods are bound to the PVC:
kubectl describe pvc <pvc_name>Specify
<pvc_name>— the name of the PersistentVolumeClaim. -
Delete the pods that are using the PVC:
kubectl delete pod <pod_name>Specify
<pod_name>— the pod name. -
Delete the PVC to which the PV is bound:
kubectl delete pvc <pvc_name>Specify
<pvc_name>— the name of the PersistentVolumeClaim.