Documentation Index

Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt

Use this file to discover all available pages before exploring further.

Block Storage CSI

Prev Next

The latest service changes have not yet been reflected in this content. We will update the content as soon as possible. Please refer to the Korean version for information on the latest updates.

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 Kubernetes Liveness Probe check. 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 the Container Storage Interface (CSI) as its 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 by the Kubernetes version:

Service\Kubernetes Version 1.16+
Create volume Supported
Delete volume Supported
Expand volume (resize) Supported
Attach volume to server Supported
Detach 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 allocatable capacity are 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 a 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 is displayed 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: CB1
  csi.storage.k8s.io/fstype: ext4
  • 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: Configures when volume binding and dynamic provisioning are performed. The default value is "Immediate."
Mode Description
Immediate Performed when a PVC is created.
WaitForFirstConsumer Performed when a Pod is created.
  • reclaimPolicy: Configures the policy for reusing or deleting a PersistentVolume when the PVC is deleted. 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: You can enable expansion of a PersistentVolumeClaim 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.

  • parameters.csi.storage.k8s.io/fstype: You can select the file system type.
Type Description
ext4 For Ubuntu, it is recommended to use ext4.
xfs For NAVIX, it is recommended to use xfs.

Change the default StorageClass

To change the default StorageClass of a created StorageClass object, see Changing the default StorageClass.

CSI Controller

The CSI controller is an interface responsible for operations such as volume creation, deletion, attachment, detachment, and snapshot management.

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

A CSI node runs on each Kubernetes worker node and is responsible for operations 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: The 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 name of the storage to mount in volumeMounts, and enter the mount path in mountPath.
    • spec.volumes: Enter the name of the PersistentVolumeClaim in persistentVolumeClaim.claimName to define the storage to be mounted to the container.

Mount an already created block storage to a pod

If block storage has already been 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.fsType: Enter the file system type of the existing block storage.
    • csi.volumeHandle: Enter the 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 to 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 a PersistentVolumeClaim to mount the volume to be used.

    • volumes.persistentVolumeClaim.claimName: Enter the name of the PersistentVolumeClaim to use.

Delete PersistentVolumeClaim

Kubernetes PersistentVolumeClaims are not deleted automatically when associated resources such as Deployments, StatefulSets, ReplicaSets, or Pods are deleted. You must use a separate command to delete them.

To check and delete PersistentVolumeClaims, use the following commands:

  • View PVCs
$ kubectl --kubeconfig $KUBE_CONFIG get pvc
  • Delete PVCs
$ 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 to request creation of a new 10 GB NAS volume:

    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 to request creation of a new 10 GB NAS volume:

    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.