Managing storage classes
The storage class (StorageClass) allows administrators to divide storages they provide into classes with defined parameters. Classes differ by the disk type and pricing policy.
Alert
The storage usage cost depends on its disk type. Check out the Yandex Compute Cloud disk prices before creating a storage.
Managed Service for Kubernetes has the following storage classes available that differ by the disk type:
yc-network-hdd(default): Network HDD storage (network-hdd).yc-network-ssd: Network SSD storage (network-ssd).yc-network-ssd-nonreplicated: Enhanced performance non-replicated SSD storage (network-ssd-nonreplicated).yc-network-ssd-io-m3: Enhanced performance network SSD storage (network-ssd-io-m3).
Alert
Non-replicated disks have no redundancy. If a disk fails, its data will be permanently lost. Learn more in Non-replicated disks and ultra high-speed network storages with three replicas (SSD).
Each storage is created with the following parameters:
- Volume Binding Mode
:WaitForFirstConsumer. - Reclaim Policy
:Delete.
For these classes, you can only use PersistentVolumeClaim and PersistentVolume in ReadWriteOnce access mode
You can create your own storage class as well as update the default storage class.
First, install kubectl
Note
The yc-network-nvme class is deprecated; use yc-network-ssd instead.
Create a storage class
-
Save the storage class creation specification to a YAML file named
my-sc-hdd.yaml:Learn more about the storage class creation specification format.
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: my-sc-hdd provisioner: disk-csi-driver.mks.ycloud.io volumeBindingMode: WaitForFirstConsumer parameters: type: network-hdd csi.storage.k8s.io/fstype: ext4 allowVolumeExpansion: false reclaimPolicy: Retain -
Run this command:
kubectl create -f my-sc-hdd.yamlResult:
storageclass.storage.k8s.io/my-sc-hdd created -
Check that the storage class was created:
kubectl get storageclassResult:
NAME PROVISIONER AGE my-sc-hdd disk-csi-driver.mks.ycloud.io 76s yc-network-hdd (default) disk-csi-driver.mks.ycloud.io 16m yc-network-ssd disk-csi-driver.mks.ycloud.io 16m
Format of a storage class creation specification
Each StorageClass object contains the parameters, allowVolumeExpansion, and reclaimPolicy properties used for dynamic allocation of PersistentVolume.
The structure of the YAML file is as follows:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: <storage_class_name> # Used to access a storage class.
provisioner: <provider_name>
volumeBindingMode: WaitForFirstConsumer
parameters: # Storage class parameters.
type: <disk_type>
csi.storage.k8s.io/fstype: <file_system_type>
allowVolumeExpansion: <allow_volume_expansion>
reclaimPolicy: <reclaim_policy>
The acceptable parameter values include:
parameters:type:network-hdd,network-ssd,network-ssd-nonreplicated, ornetwork-ssd-io-m3.csi.storage.k8s.io/fstype:ext2,ext3, orext4.
reclaimPolicy:RetainorDelete.allowVolumeExpansion:trueorfalse.
Update the default storage class
-
Check which storage class is set as default: next to its name, you will see
defaultin a parenthesis.kubectl get storageclassResult:
NAME PROVISIONER AGE my-sc-hdd disk-csi-driver.mks.ycloud.io 76s yc-network-hdd (default) disk-csi-driver.mks.ycloud.io 16m yc-network-ssd disk-csi-driver.mks.ycloud.io 16m -
Change the
storageclass.kubernetes.io/is-default-classparameter of the default storage class tofalseto remove its default class status:kubectl patch storageclass yc-network-hdd \ -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}' -
Check that
yc-network-hddis no longer the default storage class:kubectl get storageclassResult:
NAME PROVISIONER AGE my-sc-hdd disk-csi-driver.mks.ycloud.io 2m36s yc-network-hdd disk-csi-driver.mks.ycloud.io 17m yc-network-ssd disk-csi-driver.mks.ycloud.io 17m -
Specify a new default storage class, e.g.,
my-sc-hdd:kubectl patch storageclass my-sc-hdd \ -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' -
Check that
my-sc-hddis the default storage class now:kubectl get storageclassResult:
NAME PROVISIONER AGE my-sc-hdd (default) disk-csi-driver.mks.ycloud.io 4m21s yc-network-hdd disk-csi-driver.mks.ycloud.io 19m yc-network-ssd disk-csi-driver.mks.ycloud.io 19m