- Print
- PDF
Block storage CSI
- Print
- PDF
Available in VPC
If files are added to a running container, then 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, resizing, etc.
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, then a block storage of 20 GB will be created by default. The minimum and maximum capacity assignable is as follows.
- Minimum: 10 GB
- Maximum: 2,000 GB
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 below.
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
: It is true when the storage class is default. If a different value other thantrue
is entered or there's no annotation, then the value it has isfalse
.volumeBindingMode
: The point of action for volume binding and dynamic provisioning can be set. The default isImmediate
.
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 thePersistentVolume
in use is secured again or deleted when PVC is deleted at the end of its use. The default isDelete
.
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 totrue
.parameters.type:
: The block storage type can be chosen betweenSSD
andHDD
. The default isSSD
.
The block storage secured again with the Retain
policy can be terminated through NAVER Cloud Platform console or API.
Change default storage class
To change the default storage class content of a created StorageClass object, refer to 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, snapshot, etc.
To check the CSI controller, use the command shown below to check the Deployment object in the kube-system
namespace.
$ kubectl --kubeconfig $KUBE_CONFIG get deploy -n kube-system
CSI Node
CSI node is a node corresponding to each of Kubernetes worker nodes. It's in charge of actions such as volume format, mounting, unmounting, etc.
To check CSI node, use the command shown below 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 yaml code shown below. 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 theReadWriteOnce
mode is supported in NAVER Cloud Platform. Mounting is performed in a way that a single node can read/write on the volume.Resources
: size of the storage to be created. The default value is 20 GB, andGi
can be used to enter a value between 10 GB to 2,000 GB in the units of 10 GB.
Assign a new volume to a pod
Use the yaml code shown below to create a new block storage and mount it.
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 tovolumeMounts
, and enter the mounting path tomountPath
.spec.volumes
: Enter the name ofPersistentVolumeClaim
topersistentVolumeClaim.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, then you can use the storage to create a PersistentVolume
and mount it.
Use the yaml code shown below to create a PersistentVolume using the already created block storage and mount it to a pod.
kind: PersistentVolume
apiVersion: v1
metadata:
name: volume-existing-01
annotations:
pv.kubernetes.io/provisioned-by: blk.csi.ncloud.com # Provisioner name to be linked 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
Enter information so the existing block storage can be used by Kubernetes clusters.storageClassname
: Enternks-block-storage
, which is the storage class of NAVER Cloud Platform.capacity.storage
: Enter the capacity of the existing block storage.accessModes
: EnterReadWriteOnce
.csi.driver
: Enterblk.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"
, so no formatting is to be done and it will be mounted with the existing data.
kind: PersistentVolumeClaim
CreatePersistentVolumeClaim
to bind with the created PersistentVolume.resources.storage
: Enter the size of the existing block storage.storageClassname
: Enternks-block-storage
, which is the name of block storage class.volumeName
: Enter the name of the createdPersistentVolume
.
kind: Pod
SpecifyPersistentVolumeClaim
which is a volume request to mount the volume to use.volumes.persistentVolumeClaim.claimName
: Enter a name for thePersistentVolumeClaim
to specify.
Remove PersistentVolumeClaim
Kubernetes's PersistentVolumeClaim
is not deleted, even when the request resources are deleted such as deployment, StatefulSet, ReplicaSet, pod, etc. A separate command is required to delete it.
Use the following commands separately to check PersistentVolumeClaim
and to remove it.
- 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 persists.
You can delete the actual volume on the Naver Cloud Platform console.
Resize volume
NAVER Cloud Platform's block storage provides the offline resizing feature 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.
The following describes how to resize a block storage's volume. The example below uses a block storage volume of 10 GB in size.
Use the yaml code shown below 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 command shown below to adjust the number of replicas to 0.
$ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=0 deployment/my-csi-app
Run the command shown below 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 command below to check if the Condition of
PersistentVolumeClaim
isFileSystemResizePending
.~> 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 command shown below to adjust the number of replicas back to 1.
$ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=1 deployment/my-csi-app
(Optional) Run the command shown below to check if the pod's status has been changed to
Running
.$ kubectl --kubeconfig $KUBE_CONFIG get po
Create snapshot and restore volume
Create volume snapshot
Run the command shown below to create a PersistentVolume
's snapshot.
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: csi-nks-test-snapshot
spec:
source:
persistentVolumeClaimName: csi-pod-pvc
metadata.name
: Enter a name for the snapshot to be created.spec.source.persistentVolumeClaimName
: Enter the name of thePersistentVolumeClaim
bound to thePersistentVolume
to create the snapshot for.
VolumeSnapshot
is a Custom Resource Definition (CRD) defined by the CSI. Refer to the following link for details.
Check volume snapshot created
Run the command shown below to check the volume snapshot created.
$ kubectl --kubeconfig $KUBE_CONFIG get volumesnapshot
Delete volume snapshot created
Run the command shown below to delete the created volume snapshot after checking.
$ kubectl --kubeconfig $KUBE_CONFIG get volumesnapshot
NAME AGE
csi-nks-test-snapshot 17h
$ kubectl --kubeconfig $KUBE_CONFIG delete volumesnapshot csi-nks-test-snapshot
Restore volume from created volume snapshot
You can restore volumes by requesting volume creation using volume snapshots.
Use the following yaml code to restore a volume using a volume snapshot.
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 restore.spec.datasource.kind
: EnterVolumeSnapshot
, which is the resource name for the volume snapshot to restore.spec.datasource.apiGroup
: Entersnapshot.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 thePersistentVolumeClaim
's name, which is the requested volume information.