Skip to main content

Persistent volumes in a Managed Kubernetes cluster

For your information

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

For your information

Creating a persistent volume via the Topology-Aware Volume Provisioning mechanism is not available.

  1. Create a StorageClass or use an existing StorageClass.
  2. Create a PersistentVolumeClaim.
  3. 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.

  1. Create a YAML file with a manifest for the StorageClass object.

    Example of a StorageClass manifest for a single pool segment
    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
    name: fast-ru-1
    provisioner: cinder.csi.openstack.org
    parameters:
    type: fast.ru-1a
    fsType: ext4
    allowVolumeExpansion: true

    Here, fast.ru-1a is the StorageClass type.

    Example of a StorageClass manifest for multiple segments of the same pool
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
    name: fast-ru-1
    provisioner: cinder.csi.openstack.org
    parameters:
    type: fast.ru-1
    volumeBindingMode: WaitForFirstConsumer
    allowedTopologies:
    - matchLabelExpressions:
    - key: topology.cinder.csi.openstack.org/zone
    values: ["ru-1a","ru-1b","ru-1c"]

    Where:

    • fast.ru-1 is the StorageClass type;
    • "ru-1a","ru-1b","ru-1c" are the pool segments in which a persistent volume can be created with this StorageClass.
  2. 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.

  3. Ensure the StorageClass object is created:

    kubectl get sc

    A list of created StorageClass objects will appear in the response. For example:

    NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
    fast-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:

Network volume typeName in StorageClass
HDD Basicbasic
SSD Basicbasicssd
SSD Universaluniversal
SSD Universal v2universal2
SSD Fastfast
SSD Fast v2fast2

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

For your information

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.

  1. Create a YAML file with a manifest for a PersistentVolumeClaim (PVC) object.

    Example manifest:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: my-pv-claim
    spec:
    storageClassName: fast-ru-1
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 10Gi

    The 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.

  2. 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.

  1. Create a YAML file with a manifest to create a new pod with a persistent volume.

    Example manifest:

    apiVersion: v1
    kind: Pod
    metadata:
    name: nginx
    labels:
    app: webservice
    spec:
    containers:
    - name: nginx
    image: library/nginx:1.17-alpine
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: "/var/www/html"
    name: data
    volumes:
    - name: data
    persistentVolumeClaim:
    claimName: my-pv-claim

    When creating a pod with the securityContext.fsGroup parameter, the persistent volume will not be mounted with the corresponding GID. To resolve this issue, add fsType: ext4 to the StorageClass parameters.

  2. 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.

  3. Check that the PersistentVolume is created:

    kubectl get pv

    A list of PersistentVolumes will appear in the response. For example:

    NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
    pvc-f171f94c-0d38-41be-947e-2f5d7e46a6c3 10Gi RWO Delete Bound default/my-pv-claim fast-ru-1 97s

Increase a persistent volume

  1. Check the amount of occupied space in the PersistentVolumeClaim.
  2. Ensure there are sufficient quotas to increase the PersistentVolume.
  3. Allow volume expansion in the StorageClass settings.
  4. Delete pods with the volume that needs to be increased.
  5. 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

  1. Check which pods are using the PVC:

    kubectl describe pvc <pvc_name>

    Specify <pvc_name> — the name of the PersistentVolumeClaim.

  2. Delete the pods that are using the PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> — the pod name.

5. Modify the PersistentVolumeClaim manifest

  1. Open the YAML file with the PersistentVolumeClaim manifest and modify the storage: parameter:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: my-pv-claim
    spec:
    storageClassName: fast-ru-1
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 10Gi
  2. Apply the manifest:

    kubectl apply -f <pvc_name>

    Specify <pvc_name> — the name of the PersistentVolumeClaim.

  3. Run the pod using this PVC.

    Example manifest:

    apiVersion: v1
    kind: Pod
    metadata:
    name: nginx
    labels:
    app: webservice
    spec:
    containers:
    - name: nginx
    image: library/nginx:1.17-alpine
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: "/var/www/html"
    name: data
    volumes:
    - name: data
    persistentVolumeClaim:
    claimName: my-pv-claim
  4. 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.

  1. Check which pods are bound to the PVC:

    kubectl describe pvc <pvc_name>

    Specify <pvc_name> — the name of the PersistentVolumeClaim.

  2. Delete the pods that are using the PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> — the pod name.

  3. Delete the PVC to which the PV is bound:

    kubectl delete pvc <pvc_name>

    Specify <pvc_name> — the name of the PersistentVolumeClaim.