Managing storage classes
Storage class (StorageClass
) allows administrators to divide the stores 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
: Improved-performance non-replicated SSD storage (network-ssd-nonreplicated
).yc-network-ssd-io-m3
: Improved-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).
Each storage is created with the following parameters:
- Volume Binding Mode
:WaitForFirstConsumer
. - Reclaim Policy
:Delete
.
These classes allow you to 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 in the
my-sc-hdd.yaml
YAML file: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.yaml
Result:
storageclass.storage.k8s.io/my-sc-hdd created
-
Check that the storage class was created:
kubectl get storageclass
Result:
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 parameters
, allowVolumeExpansion
, and reclaimPolicy
, which are used for dynamic PersistentVolume
object allocation.
YAML file structure:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: <storage_class_name> # Used for accessing the storage class.
provisioner: <provider_name>
volumeBindingMode: WaitForFirstConsumer
parameters: # Storage class parameters.
type: <disk_type>
csi.storage.k8s.io/fstype: < file_system_type>
allowVolumeExpansion: <enable_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
:Retain
orDelete
.allowVolumeExpansion
:true
orfalse
.
Change the default storage class
-
Check which storage class is assigned by default:
default
is shown next to its name in parentheses.kubectl get storageclass
Result:
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-class
parameter of the default storage class tofalse
, to remove its status as the default class:kubectl patch storageclass yc-network-hdd \ -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
-
Check that
yc-network-hdd
is no longer the default storage class:kubectl get storageclass
Result:
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-hdd
is the default storage class:kubectl get storageclass
Result:
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