Block Storage CSI

Prev Next

Available in VPC

Note

Depending on the hypervisor used by your cluster nodes, either XEN block storage or KVM block storage is provided.
For information on each storage type and its performance, see Block Storage overview.

If you add files 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

Here are the versions of CSI provided by NAVER Cloud Platform and compatible Kubernetes versions:

Ncloud CSI Driver\Kubernetes Version 1.16 1.17+
v1.2.x Supported Not supported
v2.1.x Not supported Supported

The following storage services are supported in Kubernetes version:

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 allocate Kubernetes block storage capacity in 10 GB increments through CSI. If you do not set a volume size, the block storage is created with the default size of 20 GB. The minimum and maximum capacity assignable is as follows:

XEN KVM
Minimum 10 GB 10GB
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" if the storage class is default. If a different value other than "true" is entered or if there is no annotation, the value is "false".
  • volumeBindingMode: Configure the point of action for volume binding and dynamic provisioning. The default value is "Immediate".
Mode Description
Immediate Acts when a PVC is created.
WaitForFirstConsumer Acts when a pod is created.
  • reclaimPolicy: Configure the policy to resecure or delete PersistentVolume when PVC is deleted at the end of its use. The default value is "Delete".
Policy Description
Retain When the PVC is deleted, the bound PV is changed to a reusable state, and the data in the block storage is retained.
Delete When the PVC is deleted, the bound PV is deleted, and the block storage is returned.
Note

The block storage resecured with the Retain policy can be returned through the NAVER Cloud Platform console or API.

  • allowVolumeExpansion: PersistentVolumeClaim can be extended by setting this value to "true".
  • parameters.type:: The block storage type can be selected.
Hypervisor Available block storage types
XEN SSD(Default), HDD
KVM CB1(Default), FB1, CB2, FB2
Note

Block storages of CB2/FB2 types are available for Kubernetes version 1.30 or higher.

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 command below to check the relevant pod in the kube-system namespace.

$ kubectl --kubeconfig $KUBE_CONFIG get pods -n kube-system -l app=csi-nks-controller

CSI Node

CSI node corresponds to each of the Kubernetes worker nodes. It is responsible for actions such as volume formatting, mounting, and unmounting.

To check CSI nodes, run this command to view the related pods in the kube-system namespace.

$ kubectl --kubeconfig $KUBE_CONFIG get pods -n kube-system -l app=csi-nks-node

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 checks the PVC and automatically creates the required PersistentVolume (PV).

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 size is 20 GB, and you can enter a value in Gi between 10 GB and 2,000 GB in 10 GB increments.
Note

IOPS and throughput vary depending on the storage size and server specifications. For more information, see 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 a 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 integrated 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 the information to use an existing block storage in Kubernetes cluster.

    • 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 instance ID of the existing block storage.
    • csi.volumeAttributes: Enter blk.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 PersistentVolumeClaim to specify.

Remove PersistentVolumeClaim

Kubernetes' PersistentVolumeClaim is not deleted, even when the requested resources such as deployment, StatefulSet, ReplicaSet, and pod are deleted. You need a separate command 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
Caution

In the case of volumes set with return 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 an offline resizing feature for the already created volumes.

Caution

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. To avoid such interruptions, you should set the volume's capacity to a sufficient size when initially creating it so that it will not need resizing.

To resize a block storage's volume: The following example uses a block storage volume of 10 GB in size:

  1. 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
    
  2. Run the following command to adjust the number of replicas to 0:

    $ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=0 deployment/my-csi-app
    
  3. Run the following command to change the PersistentVolumeClaim volume request size from 10 GB to 20 GB.

    kubectl --kubeconfig $KUBE_CONFIG patch pvc csi-deployment-pvc -p '{"spec" :{"resources" :{"requests" :{"storage" :"20Gi" }}}}'
    
  4. 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: 20Gi
      storageClassName: nks-block-storage
      volumeName: pvc-xxx
    status:
      capacity:
        storage: 10G
      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
    
  5. Run the following command to adjust the number of replicas back to 1:

    $ kubectl --kubeconfig $KUBE_CONFIG scale --replicas=1 deployment/my-csi-app
    
  6. (Optional) Run the following command to check that the pod STATUS has changed to "Running".

    $ kubectl --kubeconfig $KUBE_CONFIG get po
    

Resize volume (KVM)

NAVER Cloud Platform's KVM block storage provides an online resizing feature for the already created volumes.

To resize a block storage's volume: The following example uses a block storage volume of 10 GB in size:

  1. 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
    
  2. Run the following command to change the PersistentVolumeClaim volume request size from 10 GB to 20 GB.

    kubectl --kubeconfig $KUBE_CONFIG patch pvc csi-deployment-pvc -p '{"spec" :{"resources" :{"requests" :{"storage" :"20Gi" }}}}'
    
  3. (Optional) Run the following command to check that the PersistentVolumeClaim size has been set to 20 GB:

    $ kubectl --kubeconfig $KUBE_CONFIG describe pvc csi-deployment-pvc
    

Create snapshot and recover volume

Create volume snapshot

Caution

Starting from nks v1.33, Snapshot v1 is supported, and v1beta1 will be deprecated. For versions earlier than v1.33, use v1beta1 (snapshot.storage.k8s.io/v1beta1).

To create a snapshot of the PersistentVolume, run the following command:

apiVersion: snapshot.storage.k8s.io/v1
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.
Note

VolumeSnapshot is a custom resource definition (CRD) defined by CSI. For more information, see the following:

Snapshot-Restore-Feature

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 apiGroup of the snapshot.
    • resources.request.storage: Enter the same value as the volume snapshot size.
  • Pod
    • claimName: Enter the PersistentVolumeClaim's name, which is the requested volume information.