A persistent volume is used as storage in the cluster.
Managed Kubernetes uses Selectel Cloud platform volumes, so they are subject to the same restrictions. Learn more about network volumes of the Cloud platform. All created volumes are displayed in the Volumes section of the Cloud platform Control panel.
A persistent volume must be created in the same zone as the cluster, using PersistentVolumeClaim (a request for creating a volume).
Working with volumes is possible only in ReadWriteOnce mode.
Please note that creating a volume using Topology-Aware Volume Provisioning is not available.
Creating a Persistent Volume
A Manifest for Creating a StorageClass
A 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. You must specify the type and zone of the volume in the Storage Class object. For example, to create fast volumes in the ru-1a zone, add the following fields in the StorageClass description in the parameters section:
type: fast.ru-1a availablity: ru-1a
The fast, basic, and universal volume types correspond to network volumes in the Selectel Cloud platform.
When creating a cluster in the Control panel, one StorageClass with a fast network volume will be automatically created in the zone corresponding to the zone of the cluster node group. When creating a cluster through Terraform or using the API, StorageClass is not created automatically.
To see which StorageClass were created (for OpenStack cinder), run the following command:
$ kubectl get sc NAME PROVISIONER AGE fast.ru-3a cinder.csi.openstack.org 2d19h
An example of a StorageClass manifest for a fast volume in the ru-1a zone:
# fast.ru-1a.yaml 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 allowVolumeExpansion: true
You can use other ready-made StorageClass manifests to create a PersistentVolume.
A Manifest for Creating a PersistentVolumeClaim
Create a PersistentVolumeClaim manifest using StorageClass:
# my-pv-claim.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pv-claim spec: storageClassName: fast.ru-3a accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
Please note that the zone in the PVC manifest must correspond to the zone of the node to which it must be connected. When using multiple zones for cluster and PVC nodes, you will need to specify the Pod objects binding to the zone in their description.
A Manifest for Creating a Pod
If you create a Pod with a persistent volume, the volume remains when the pod is deleted.
A manifest for creating a persistent volume pod:
# nginx-with-volume.yaml 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
Information for Pods with securityContext.fsGroup
When creating a pod with the
securityContext.fsGroup parameter, the volume will not be mounted with the corresponding GID. To fix this problem, add
fsType: ext4 in StorageClass
Creating PVC and Pod
To create a request and a pod, run:
kubectl create -f my-pv-claim.yaml kubectl create -f nginx-with-volume.yaml
Make sure that the volume is connected:
$ kubectl get pv 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-3a 97s