Managing storage classes
Storage class (StorageClass) allows administrators to divide the storages they provision into classes with defined parameters. Classes vary by disk type and pricing policy.
Alert
The storage usage cost depends on its disk type. See the Yandex Compute Cloud disk prices prior to 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 irretrievably lost. For more information, see Non-replicated disks and ultra high-speed network storages with three replicas (SSD).
All storages are created with the following parameters:
- Volume Binding Mode
:WaitForFirstConsumer. - Reclaim Policy
:Delete.
Under these classes, you can use PersistentVolumeClaim and PersistentVolume only in ReadWriteOnce access mode
You can create your own storage class as well as change the default storage class.
Before you start, install kubectl
Note
yc-network-nvme 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
Create a storage class specification format
Each StorageClass object contains the parameters named parameters, allowVolumeExpansion, and reclaimPolicy used for dynamic allocation of the PersistentVolume object.
YAML file structure:
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>
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.
Change the default storage class
-
Check which storage class is assigned by default: next to its name, you will see
defaultin parentheses.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: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