NAS volume CSI examples

Prev Next

Available in VPC

Here is an example of how to allocate volumes using various methods based on the CSI usage described in NAS Volume CSI.

Add NAS volume

To add NAS volume through the NAS CSI driver, request PersistentVolumeClaim (PVC) through the following yaml code. The NAS CSI driver checks the PVC and automatically generates the necessary PersistentVolume (PV).

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi
  • AccessMode: CSI supports various access modes.
Mode Description
ReadWriteOnce Mounts volume as read-write on a single nod
ReadOnlyMany Mounts volume as read only on multiple nodes
ReadWriteMany Mounts volume as read-write on multiple nodes
  • Resources: size of the storage to be created. The default value is 500 GB, and Gi can be used to enter a value between 500 GB to 10,000 GB in the units of 100 GB.

Assign a new volume to a pod

Use the following yaml code to create a new NAS volume and mount it.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi
---
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: nas-csi-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.
Caution

If you delete a cluster while an NAS volume is mounted on a pod, the NAS volume will not be deleted automatically. In such cases, it needs to be terminated through NAVER Cloud Platform console or API.

Mounting a single NAS volume to multiple pods

This is an example of creating a new NAS volume and mounting it to 2 pods to share the volume.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi
---
kind: Pod
apiVersion: v1
metadata:
  name: my-csi-app-1
spec:
  containers:
    - name: my-frontend
      image: busybox
      volumeMounts:
      - mountPath: "/data"
        name: my-volume
      command: [ "sleep", "1000000" ]
  volumes:
    - name: my-volume
      persistentVolumeClaim:
        claimName: nas-csi-pvc
---
apiVersion: v1
kind: Pod
metadata:
  name: my-csi-app-2
spec:
  containers:
    - name: my-frontend
      image: busybox
      volumeMounts:
      - mountPath: "/data"
        name: my-volume
      command: [ "sleep", "1000000" ]
  volumes:
    - name: my-volume
      persistentVolumeClaim:
        claimName: nas-csi-pvc

Mount an already created NAS volume to a pod

Creates a volume in NAS with NFS protocol.

Once an NAS volume is created, check the IP address and path information in the mount information.

Use the yaml code shown below to create a StorageClass using the already created NAS volume and mount it to a pod.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: static-nks-nas-csi
provisioner: nas.csi.ncloud.com
parameters:
  server: __NAS_IP__
  share: __NAS_PATH__
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
mountOptions:
  - hard
  - nolock
  - nfsvers=3
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: static-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: static-nks-nas-csi
---
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: static-pvc
  • kind: StorageClass
    Enter the information to use an existing NAS volume in the Kubernetes cluster.

    • provisioner: enter nas.csi.ncloud.com, provisioner of NAVER Cloud Platform NAS volume.
    • parameters.server: enter the IP of the existing NAS volume mount information.
    • parameters.path: enter the path of the existing NAS volume mount information.
    • reclaimPolicy: must set as Retain to prevent deletion of NAS when PVC is deleted at the end of its use.
  • kind: PersistentVolumeClaim
    Create PersistentVolumeClaim to bind with the created PersistentVolume.

    • resources.storage: this is a required field. Enter the size of the NAS volume previously created. However, the PVC size is dependent on the NAS volume size, so the entered value is meaningless.
    • storageClassname: enter static-nks-nas-csi, which is the name of the NAS 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.
Caution

In the case of NAS volumes with return protection, PersistentVolumeClaim is deleted, but the actual volume is maintained.
You can delete the actual NAS volume on the NAS console.

Resize volume

NAVER Cloud Platform's NAS volume provides the resizing feature for the already created volumes.

To resize an NAS volume, follow these steps: The example below uses an NAS volume of 500 GB in size.

  1. Use the following yaml code to create a new block storage volume of 500 GB.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-deployment-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi
---
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
  1. Run the following command to adjust PersistentVolumeClaim's volume request size from 500 GB to 600 GB:
kubectl --kubeconfig $KUBE_CONFIG patch pvc csi-deployment-pvc -p '{"spec":{"resources":{"requests":{"storage":"600Gi"}}}}'

Use a StorageClass with a reclaimPolicy of Retain

A StorageClass with a reclaimPolicy of Retain preserves the actual storage resource even if the associated resource is deleted. This feature prevents data loss and provides the flexibility to manage or recover data manually. Once a StorageClass is created, it is difficult to change its settings. If you need to change the settings, you must create a new StorageClass instead of modifying an existing StorageClass. When using the Retain policy, you need to manually manage and clean up storage resources associated with deleted PVs

With the yaml code in the example below, you can use a StorageClass that has a reclaimPolicy of Retain.

allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-retain
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
reclaimPolicy: Retain 
volumeBindingMode: WaitForFirstConsumer

Use StorageClass with the zone number specified

Caution

StorageClass with the zone number specified is available for NAS CSI version 2.0.1 or higher.

The NAS CSI driver creates an NAS volume in the same zone as Kubernetes. However, you can create an NAS volume in a specific zone in the same region by specifying zoneNo in StorageClass. You can create an NAS volume by specifying ZoneNo through the yaml code, which is used as an example below.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-kr-2
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  zoneNo: "3"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi-kr-2
---
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: nas-csi-pvc
  • kind: StorageClass
    • parameters.zoneNo: enter ZoneNo for creating an NAS volume

      Region Zone ZoneNo
      Korea KR-1 2
      Korea KR-2 3
      Singapore SGN-4 74
      Singapore SGN-5 75
      Japan JPN-4 84
      Japan JPN-5 85

Use StorageClass for encrypted NAS volumes

Caution

StorageClass for the encrypted NAS volume is available for NAS CSI version 2.0.2 or higher.

NAS CSI driver creates NAS volumes without volume encryption by default. However, you can create the encrypted NAS volumes by specifying encryption in the StorageClass. You can create an encrypted NAS volume through the yaml code, which is used as an example below.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-encryption
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  encryption: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi-encryption
---
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: nas-csi-pvc

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 static-pvc

Accessing an NAS directly from a Pod

If you want to directly access an NAS without using NAS-CSI, you can use NFS to mount the NAS directly from a Pod. The example below shows how to use the NFS volume type to mount the NAS server directly. Enter the IP address of the NAS in the server field, and enter the path of the NAS in the path field. You can also specify the path to be used within the container using volumeMounts.

Caution

As NAS-CSI is not used, NAS ACL must be manually registered.

kind: Deployment
metadata:
  name: my-csi-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-csi-app 
  template:
    metadata:
      labels:
        app: my-csi-app
    spec:
      containers:
      - name: my-csi-app 
        image: nginx 
        volumeMounts:
        - name: web
          mountPath: /web
        - name: was
          mountPath: /was
      volumes:
      - name: web
        nfs:
          server: __NAS_IP__
          path: __NAS_PATH__/web
          readOnly: false
      - name: was
        nfs:
          server: __NAS_IP__
          path: __NAS_PATH__/was 
          readOnly: false