Skip to main content
Permanent volumes
Last update:

Permanent volumes

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 volumes from the Selectel cloud platform. You can create a persistent volume on your local disk, but when you delete a node, the data will be deleted.

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

All persistent volumes are displayed in Control Panel under Cloud PlatformDisks.

Create a permanent volume

For your information

Creation via the Topology-Aware Volume Provisioning mechanism is not available.

  1. Create StorageClass or use an existing StorageClass.
  2. Create PersistentVolumeClaim.
  3. Create-pod-with-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 create cluster, one StorageClass will be automatically created with a fast network volume 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 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

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

The disk types correspond to network volumes of the Selectel Cloud Platform:

network volume 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 PersistentVolumeClaim

For your information

Working with volumes is only possible in ReadWriteOnce mode — one volume can only be mounted to one node, with only one sub mounted to a persistent volume. If multiple pods are connected to a single PV, data may be corrupted. To work with ReadWriteMany mode (mount a volume to multiple nodes), you can mount 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 you plan to connect this PVC. If you use multiple pools for cluster nodes and PVCs, specify in the description of Pod objects their binding to the pool.

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

    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

    If you create 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 a yaml file with a manifest to create a new persistent volume feed.

  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 there are enough quotas to increase PersistentVolume.
  3. Allow volume enlargement in StorageClass settings.
  4. Delete pods-with-volume-to-be-increased.
  5. Modify PersistentVolumeClaim manifest

1. Check the amount of occupied space in PVC

Recognize the amount of occupied space in the PVC:

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

Specify:

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

2. Check quotas

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

3. Allow increasing the persistent volume

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

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 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. Read more about the Reclaim policy in the Reclaiming article of the Kubernetes documentation.

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

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

    kubectl delete pvc <pvc_name>

    Specify <pvc_name> is the name of the PersistentVolumeClaim.