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 objects are used to manage persistent volumes PersistentVolume (PV), PersistentVolumeClaim (PVC) и StorageClass.

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

After creations of the permanent volume, you can enlarge и delete.

All persistent volumes are displayed in control panels under Cloud platformDisks.

Create a permanent volume

For your information

Creation through the mechanism Topology-Aware Volume Provisioning unavailable.

  1. Create StorageClass Or use an existing StorageClass.
  2. Create PersistentVolumeClaim.
  3. Create a sub with a persistent volume.

Create StorageClass

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

At cluster creation will automatically create one StorageClass 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 — StorageClass type.

    You can use other ready-made StorageClass manifests.

  2. Apply the manifest:

    kubectl apply -f <storage-class.yaml>

    Specify <storage-class.yaml> — name of the yaml file with the manifest for creating 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

The StorageClass type format is. <тип диска>.<сегмент пула, в котором он расположен>.

Disk types correspond to network drives of Selectel's cloud platform:

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

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 mounted 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> — name of the yaml file with the manifest for creating a new PersistentVolumeClaim.

Create a sub with a persistent volume

If you create under (Pod) with a persistent volume, then 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.

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

  2. Apply the manifest:

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

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

  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. Make sure that there are enough quotas to increase PersistentVolume.
  3. Enable volume enlargement in the StorageClass settings.
  4. Delete pods with the volume to be enlarged.
  5. Modify the PersistentVolumeClaim manifest.

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 feed that uses PVC.

Check quotas

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

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

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> — PersistentVolumeClaim name.

  2. Remove pods that use PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> — the name of the pitcher.

Modify the PersistentVolumeClaim manifest

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

    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> — PersistentVolumeClaim name.

  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. Verify 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 PVC manifest specifies the parameter persistentVolumeReclaimPolicy: Delete. Read more about the Reclaim policy in the article Reclaiming Kubernetes documentation.

  1. Check which pods are bound to the PVC:

    kubectl describe pvc <pvc_name>

    Specify <pvc_name> — PersistentVolumeClaim name.

  2. Remove pods that use PVC:

    kubectl delete pod <pod_name>

    Specify <pod_name> — the name of the pitcher.

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

    kubectl delete pvc <pvc_name>

    Specify <pvc_name> — PersistentVolumeClaim name.