- Print
- PDF
Block storage CSI
- Print
- PDF
Available in VPC
The type of block storage provided (XEN or KVM) depends on the hypervisor used by your cluster nodes.
For information on each storage type and its performance, see Block storage overview.
If files are added to a running container, all files are deleted when the process is terminated or the container is restarted due to a failed health check of Kubernetes Liveness Probe. You can use the block storage for such cases to adjust the settings so that the added files will be kept, even after the process is terminated or the container is restarted.
Kubernetes block storage can be added by creating a PersistentVolumeClaim (PVC) when you deploy the container.
NAVER Cloud Platform's Ncloud Kubernetes Service provides Container Storage Interface (CSI) as a volume driver. This driver is linked with Kubernetes and supports tasks such as block storage creation, deletion, and resizing.
Supported versions and capacity
Supported versions
NAVER Cloud Platform supports the following versions of CSI and Kubernetes compatible with it:
Ncloud CSI Driver\Kubernetes Version | 1.16 | 1.17+ |
---|---|---|
v1.2.x | Supported | Not supported |
v2.1.x | Not supported | Supported |
This Kubernetes version supports the following storage services:
Service\Kubernetes Version | 1.16+ |
---|---|
Create volume | Supported |
Delete volume | Supported |
Expand volume (resize) | Supported |
Assign volume to server | Supported |
Remove volume from server | Supported |
Create snapshot | Supported |
Delete snapshot | Supported |
Assignable capacity
You can assign capacity in the units of 10 GB to Kubernetes block storage through CSI. If the volume size is not defined separately, a block storage of 20 GB will be created by default. The minimum and maximum capacity assignable is as follows:
XEN | KVM | |
---|---|---|
Minimum | 10 GB | 10 GB |
Maximum | 2 TB | 16 TB |
CSI driver details
Storage Class
Storage class is an object that specifies each storage's policy and type. NAVER Cloud Platform provides default storage class which uses block storage.
To view block storage's storage class objects, check the object named nks-block-storage from StorageClass within the kube-system namespace. It will be shown as follows:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: nks-block-storage
namespace: kube-system
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: blk.csi.ncloud.com
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
allowVolumeExpansion: true
parameters:
type: SSD
Annotations: storageclass.kubernetes.io/is-default-class
: the value is true when the storage class is default. If a different value other than true is entered or there's no annotation, the value is false.volumeBindingMode
: the point of action for volume binding and dynamic provisioning can be set. The default is Immediate.
Mode | Description |
---|---|
Immediate | Act at the point when PVC is created |
WaitForFirstConsumer | Act at the point when a pod is created |
reclaimPolicy
: you can set the policy so that the PersistentVolume in use is secured again or deleted when PVC is deleted at the end of its use. The default is Delete.
Policy | Description |
---|---|
Retain | When a PVC is deleted, the PV in use is changed to the status where it can be reused. The block storage's internal data is maintained |
Delete | When a PVC is deleted, the PV in use is deleted with it and the block storage is terminated |
allowVolumeExpansion
: PersistentVolumeClaim can be extended by setting this value to true.parameters.type:
: the block storage type can be selected between SSD and HDD. The default is SSD.
The block storage secured again with the Retain policy can be terminated through the NAVER Cloud Platform console or API.
Change default storage class
To change the default storage class content of a created StorageClass object, see Changing the default StorageClass.
CSI Controller
CSI controller is an interface that takes charge of various controls and management of a volume such as creation, deletion, assignment, removal from assignment, and snapshot.
To check the CSI controller, use the following command to check the Deployment object in the kube-system
namespace:
$ kubectl --kubeconfig $KUBE_CONFIG get deploy -n kube-system
CSI Node
CSI node corresponds to each of the Kubernetes worker nodes. It is responsible for actions such as volume format, mounting, and unmounting.
To check CSI node, use the following command to check the DaemonSet resource in the kube-system namespace:
$ kubectl --kubeconfig $KUBE_CONFIG get daemonset -n kube-system
Use CSI driver
Add block storage
To add block storage through CSI driver, request a PersistentVolumeClaim (PVC) through the following yaml code. The CSI driver will check the PVC and automatically create the PersistentVolume (PV) required.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-pod-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: nks-block-storage
AccessMode
: only the ReadWriteOnce mode is supported in NAVER Cloud Platform. Mounting is performed in a way that a single node can read/insert on the volume.Resources
: size of the storage to be created. The default value is 20 GB, and Gi can be used to enter a value between 10 GB and 2000 GB in the units of 10 GB.
IOPS and throughput vary depending on the storage size and server specifications. For more information, see the Storage specifications and Server specifications.
Assign a new volume to a pod
To create a new block storage and mount it, use the following yaml code:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-pod-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: nks-block-storage
---
kind: Pod
apiVersion: v1
metadata:
name: my-csi-app
spec:
containers:
- name: my-frontend
image: busybox
volumeMounts:
- mountPath: "/data"
name: my-volume
command: [ "sleep", "1000000" ]
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: csi-pod-pvc
- Pod
spec.container
: enter the storage name to be mounted to volumeMounts, and enter the mounting path to mountPath.spec.volumes
: enter the name of PersistentVolumeClaim to persistentVolumeClaim.claimName to define the storage to be mounted to the container.
Mount an already created block storage to a pod
If there's a block storage already created, you can use the storage to create a PersistentVolume and mount it.
To create a PersistentVolume using the already created block storage and mount it to a pod, use the following yaml code:
kind: PersistentVolume
apiVersion: v1
metadata:
name: volume-existing-01
annotations:
pv.kubernetes.io/provisioned-by: blk.csi.ncloud.com # provisioner name to be connected to the block storage
spec:
storageClassName: nks-block-storage # storage class name of the block storage
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 10Gi # block storage size
accessModes:
- ReadWriteOnce
csi:
driver: blk.csi.ncloud.com
fsType: ext4
volumeHandle: "952814" # Block Storage Instance ID
volumeAttributes:
blk.csi.ncloud.com/noformat: "true" # does not format the block storage
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-pod-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: nks-block-storage
volumeName: "volume-existing-01"
---
kind: Pod
apiVersion: v1
metadata:
name: my-csi-app
spec:
containers:
- name: my-frontend
image: busybox
volumeMounts:
- mountPath: "/data"
name: my-volume
command: [ "sleep", "1000000" ]
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: csi-pod-pvc
kind: PersistentVolume
To use an existing block storage by Kubernetes clusters, enter information.storageClassname
: enter nks-block-storage, which is the storage class of NAVER Cloud Platform.capacity.storage
: enter the size of the existing block storage.accessModes
: enter ReadWriteOnce.csi.driver
: enter blk.csi.ncloud.com, which is the name of the storage class driver.csi.volumeHandle
: enter the instance ID of the existing block storage.csi.volumeAttributes
: enterblk.csi.ncloud.com/noformat: "true"
to mount without formatting with existing data preserved.
kind: PersistentVolumeClaim
Create PersistentVolumeClaim to bind with the created PersistentVolume.resources.storage
: enter the size of the existing block storage.storageClassname
: enter nks-block-storage, which is the name of block storage class.volumeName
: enter the name of the created PersistentVolume.
kind: Pod
Specify PersistentVolumeClaim which is a volume request to mount the volume to use.volumes.persistentVolumeClaim.claimName
: enter a name for the PersistentVolumeClaim to specify.
Remove PersistentVolumeClaim
Kubernetes' PersistentVolumeClaim is not deleted, even when the requested resources are deleted such as deployment, StatefulSet, ReplicaSet, and pod. A separate command is required to delete it.
To check PersistentVolumeClaim and remove it, use the following commands separately:
- View PVC
$ kubectl --kubeconfig $KUBE_CONFIG get pvc
- Delete PVC
$ kubectl --kubeconfig $KUBE_CONFIG delete pvc csi-pod-pvc
In the case of volumes with termination protection, PersistentVolumeClaim is deleted but the actual volume is maintained.
You can delete the actual volume on the NAVER Cloud Platform console.
Resize volume (XEN)
NAVER Cloud Platform's XEN block storage provides the offline resizing function for the already created volumes.
When you perform volume resizing, the application's operation can temporarily be interrupted in the process of adjusting the number of replicas to 0 from the controller of the pod in operation. It's recommended to set the volume's capacity to a sufficient size when initially creating it so that it won't need to be resized to avoid such interruptions.
To resize a block storage's volume, follow these steps: The following example uses a block storage volume of 10 GB in size.
Use the following yaml code to create a new block storage volume of 10 GB.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: csi-deployment-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: nks-block-storage --- apiVersion: apps/v1 kind: Deployment metadata: name: my-csi-app spec: selector: matchLabels: app: my-csi-app replicas: 1 template: metadata: labels: app: my-csi-app spec: containers: - name: my-frontend image: busybox volumeMounts: - mountPath: "/data" name: my-volume command: [ "sleep", "1000000" ] volumes: - name: my-volume persistentVolumeClaim: claimName: csi-deployment-pvc
Run the following command to adjust the number of replicas to 0:
$ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=0 deployment/my-csi-app
Run the following command to adjust PersistentVolumeClaim's volume request size from 10 GB to 20 GB:
kubectl --kubeconfig $KUBE_CONFIG patch pvc csi-deployment-pvc -p '{"spec" :{"resources" :{"requests" :{"storage" :"20Gi" }}}}'
Run the following command to check if the Condition of PersistentVolumeClaim is FileSystemResizePending:
~> kubectl get pvc csi-deployment-pvc -o yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: csi-deployment-pvc namespace: default uid: 02d4aa83-83cd-11e8-909d-42010af00004 spec: accessModes: - ReadWriteOnce resources: requests: storage: 14Gi storageClassName: standard volumeName: pvc-xxx status: capacity: storage: 9G conditions: - lastProbeTime: null lastTransitionTime: 2018-07-11T14:51:10Z message: Waiting for user to (re-)start a pod to finish file system resize of volume on node. status: "True" type: FileSystemResizePending phase: Bound
Run the following command to adjust the number of replicas back to 1:
$ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=1 deployment/my-csi-app
(Optional) Run the following command to check if the pod's status has been changed to Running:
$ kubectl --kubeconfig $KUBE_CONFIG get po
Resize volume (KVM)
NAVER Cloud Platform's KVM block storage provides the online resizing function for the already created volumes.
To resize a block storage's volume, follow these steps: The following example uses a block storage volume of 10 GB in size.
Use the following yaml code to create a new block storage volume of 10 GB.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: csi-deployment-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: nks-block-storage --- apiVersion: apps/v1 kind: Deployment metadata: name: my-csi-app spec: selector: matchLabels: app: my-csi-app replicas: 1 template: metadata: labels: app: my-csi-app spec: containers: - name: my-frontend image: busybox volumeMounts: - mountPath: "/data" name: my-volume command: [ "sleep", "1000000" ] volumes: - name: my-volume persistentVolumeClaim: claimName: csi-deployment-pvc
Run the following command to adjust PersistentVolumeClaim's volume request size from 10 GB to 20 GB:
kubectl --kubeconfig $KUBE_CONFIG patch pvc csi-deployment-pvc -p '{"spec" :{"resources" :{"requests" :{"storage" :"20Gi" }}}}'
(Optional) Run the following command to check that the size of the PersistentVolumeClaim has been changed to 20 GB:
$ kubectl --kubeconfig $KUBE_CONFIG describe pvc csi-deployment-pvc
Create snapshot and recover volume
Create volume snapshot
To create a snapshot of the PersistentVolume, run the following command:
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: csi-nks-test-snapshot
spec:
source:
persistentVolumeClaimName: csi-pod-pvc
metadata.name
: enter the name for the snapshot to be created.spec.source.persistentVolumeClaimName
: enter the name of the PersistentVolumeClaim bound to the PersistentVolume to create the snapshot for.
VolumeSnapshot is a Custom Resource Definition (CRD) defined by the CSI. For more information, see the following:
Check volume snapshot created
To check the volume snapshot created, run the following command:
$ kubectl --kubeconfig $KUBE_CONFIG get volumesnapshot
Delete volume snapshot created
To delete the created volume snapshot after checking, run the following command:
$ kubectl --kubeconfig $KUBE_CONFIG get volumesnapshot
NAME AGE
csi-nks-test-snapshot 17h
$ kubectl --kubeconfig $KUBE_CONFIG delete volumesnapshot csi-nks-test-snapshot
Recover volume from created volume snapshot
You can recover volumes by requesting volume creation using volume snapshots.
To recover a volume using a volume snapshot, use the following yaml code:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-nks-test-pvc-restore
spec:
dataSource:
name: csi-nks-test-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: nks-block-storage
---
kind: Pod
apiVersion: v1
metadata:
name: csi-restore-app
spec:
containers:
- name: my-frontend
image: busybox
volumeMounts:
- mountPath: "/data"
name: my-volume
command: [ "sleep", "1000000" ]
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: csi-nks-test-pvc-restore
- PersistentVolumeClaim
spec.datasource.name
: enter the name of the volume snapshot to recover.spec.datasource.kind
: enter VolumeSnapshot, which is the resource name for the volume snapshot to recover.spec.datasource.apiGroup
: enter snapshot.storage.k8s.io, which is the snapshot's apiGroup.resources.request.storage
: Enter the same value as the volume snapshot's size.
- Pod
claimName
: enter the PersistentVolumeClaim's name, which is the requested volume information.