Skip to main content
Permanent volumes
Last update:

Permanent volumes

For your information

Cloud platform network disk-based persistent volume (PV) 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. Kubernetes uses PersistentVolume (PV), PersistentVolumeClaim (PVC), and StorageClass objects to manage persistent volumes.

For persistent volumes in Managed Kubernetes, we recommend using network disks from the Selectel cloud platform. You can create a persistent volume on a local disk, but the data will be deleted when the node is deleted.

After you create a persistent volume, you can enlarge and delete it.

You can view all persistent volumes in the Control Panel: from the top menu, click Products and select Cloud ServersDisk section.

Create a permanent volume

For your information
  1. Create a StorageClass or use an existing StorageClass.
  2. Create a PersistentVolumeClaim.
  3. Create a sub with a persistent volume.

1. Create StorageClass

The StorageClass object is used to create a PersistentVolume. StorageClass allows you to pre-describe the configuration of persistent volumes that will be needed in the cluster operation.

When a cluster is created, a single StorageClass will be automatically created with a fast network disk in the pool 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 fast disk in the ru-1a pool:

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
    name: fast.ru-1a
    provisioner: cinder.csi.openstack.org
    parameters:
    type: fast.ru-1a
    availability: ru-1a
    fsType: ext4
    allowVolumeExpansion: true

    Here fast.ru-1a is of type StorageClass.

    You can use other ready-made StorageClass manifests.

  2. Apply the manifest:

    kubectl apply -f <storage-class.yaml>

    Specify <storage-class.yaml> is the name of the manifest yaml file to create a new StorageClass.

  3. Verify that a StorageClass object has been created:

    kubectl get sc

    The response will list the created StorageClass objects:

    NAME         PROVISIONER                RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
    fast.ru-1a cinder.csi.openstack.org Delete Immediate true 16m

StorageClass type

StorageClass-type format- <disk type>.<the pool segment in which it resides>.

The disk types correspond to the Selectel Cloud Platform network disks:

Network disk typeName in StorageClass
Fast SSDfast
Basic HDDbasic
Basic SSDbasicssd
Universal SSDuniversal

For example, to create a fast disk in the ru-1a pool segment, you must add to the StorageClass description:

parameters:
type: fast.ru-1a
availability: ru-1a

2. Create a PersistentVolumeClaim

For your information

Working with volumes is possible only in ReadWriteOnce mode — one volume can be mounted to only one node, and only one pod can be connected to a persistent volume. If several pods are connected to one PV, data may be corrupted. To work with 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 the PersistentVolumeClaim (PVC) object.

    Manifesto example:

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

    The pool in the PVC manifest must match the pool of the node to which the PVC is to be connected. If you use multiple pools for cluster nodes and PVCs, specify in the description of Pod objects their pool mapping.

  2. Apply the manifest:

    kubectl apply -f <pvc.yaml>

    Specify <pvc.yaml> is the name of the manifest yaml file to create a new PersistentVolumeClaim.

3. Create a sub with a persistent volume

If you create a 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 persistent volume feed.

    Manifesto example:

    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 submission with the securityContext.fsGroup parameter, the persistent volume will not be mounted with the appropriate GID. To solve this problem, add fsType: ext4 in the StorageClass parameters.

  2. Apply the manifest:

    kubectl apply -f <pod-with-pv.yaml>

    Specify <pod-with-pv.yaml> is the name of the manifest yaml file to create a new pod with a persistent volume.

  3. Verify that PersistentVolume has been created:

    kubectl get pv

    A list of PersistentVolumes will appear in the response:

    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-1a 97s

Increase the permanent volume

  1. Check the amount of occupied space in PersistentVolumeClaim.
  2. Verify that there are enough quotas to increase PersistentVolume.
  3. Enable volume enlargement in the StorageClass settings.
  4. Delete pods with the volume you want to increase the size of.
  5. Modify the PersistentVolumeClaim manifest.

1. Check the amount of occupied space in the PVC

Recognize the amount of occupied space in the PVC:

kubectl -n <namespace> exec <pod_name> -- df -ah

Specify:

  • <namespace> — namespace where the PVC is located;
  • <pod_name> — the name of the pod that uses PVC.

2. Check quotas

To determine that there are enough resources to grow the persistent volume, check the quotas and change them if necessary.

3. Allow permanent volume enlargement

In the parameters of the StorageClass object, specify allowVolumeExpansion: true.

Manifesto example:

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 to be enlarged

  1. Check to see which pods are using PVC:

    kubectl describe pvc <pvc_name>

    Specify <pvc_name> is the name of the PersistentVolumeClaim.

  2. Remove pods that use PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> is the name of the pod.

5. Modify the PersistentVolumeClaim manifest

  1. Open the yaml file with the manifest for PersistentVolumeClaim and change the storage parameter:

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

    kubectl apply -f <pvc_name>

    Specify <pvc_name> is the name of the PersistentVolumeClaim.

  3. Run under using this PVC.

    Manifesto example:

    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. Check that PersistentVolumeClaim has been created:

    kubectl get pvc

Delete a persistent volume

If you no longer need the persistent volume, delete the PersistentVolumeClaim that was used to create the volume.

The PV will be immediately deleted if the persistentVolumeReclaimPolicy: Delete parameter is specified in the PVC manifest. For more information about the Reclaim policy, see the Reclaiming Kubernetes documentation article.

  1. Check which pods are bound to the PVC:

    kubectl describe pvc <pvc_name>

    Specify <pvc_name> is the name of the PersistentVolumeClaim.

  2. Remove pods that use PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> is the name of the pod.

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

    kubectl delete pvc <pvc_name>

    Specify <pvc_name> is the name of the PersistentVolumeClaim.