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.

NAS volume CSI examples

Prev Next

Available in VPC

This section provides examples of allocating volumes using various methods based on the CSI usage described in NAS CSI volumes.

Add NAS volume

To add a NAS volume using the NAS CSI driver, create a PersistentVolumeClaim (PVC) using the following YAML. The NAS CSI driver checks the PVC and automatically creates the required PersistentVolume (PV).

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

Assign a new volume to a Pod

To create and mount a new NAS volume, use the following YAML:

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 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.
Caution

If you delete a cluster while a NAS volume is mounted on a Pod, the NAS volume is not deleted automatically. In this case, you must return it through the NAVER Cloud Platform console or API.

Mount a single NAS volume to multiple Pods

This example shows how to create a new NAS volume and mount 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 existing NAS volume to a Pod

Create a volume in NAS using the NFS protocol.

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

To create a StorageClass using an existing NAS volume and mount it to a Pod, use the following YAML:

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 required to use an existing NAS volume in a Kubernetes cluster.

    • provisioner: Enter nas.csi.ncloud.com, the provisioner of NAVER Cloud Platform NAS volumes.
    • parameters.server: Enter the IP from the mount information of the existing NAS volume.
    • parameters.path: Enter the path from the mount information of the existing NAS volume.
    • reclaimPolicy: Set this value to Retain to prevent the NAS volume from being deleted when the PVC is deleted.
  • kind: PersistentVolumeClaim
    Create PersistentVolumeClaim to bind to the created PersistentVolume.

    • resources.storage: Enter the size of the existing NAS volume (required). However, the PVC size depends on the NAS volume size, so the entered value has no effect.
    • storageClassname: Enter static-nks-nas-csi, the name of the NAS StorageClass.
    • 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.
Caution

For NAS volumes with return protection enabled, the PersistentVolumeClaim is deleted, but the actual volume is retained.
You can delete the actual NAS volume from the NAS console.

Resize volumes

NAVER Cloud Platform's NAS volumes support resizing for existing volumes.

To resize a NAS volume: The example below uses a 500 GB NAS volume.

  1. Use the following YAML to request creation of a new 500 GB NAS volume:
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 change the PersistentVolumeClaim 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 reclaimPolicy set to Retain

A StorageClass with reclaimPolicy set to Retain preserves the actual storage resources even if related resources are deleted. This feature helps prevent data loss and allows you to manage or recover data manually. Once a StorageClass is created, its settings cannot be easily changed. If you need to change the settings, create a new StorageClass instead of modifying the existing one. When using the Retain policy, you must manually manage and clean up storage resources associated with deleted PVs.

You can use a StorageClass with reclaimPolicy set to Retain using the YAML example below:

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 a StorageClass with a specified zone number

Caution

A StorageClass with a specified zone number is available from NAS CSI version 2.0.1 or later.

The NAS CSI driver creates a NAS volume in the same zone as Kubernetes. However, you can create a NAS volume in a specific zone within the same Region by specifying zoneNo in the StorageClass. You can create a NAS volume by specifying zoneNo using the YAML 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 the ZoneNo for creating a NAS volume.
      Region Zone ZoneNo
      Korea KR-1
      Korea KR-2
      Singapore SGN-4
      Singapore SGN-5
      Japan JPN-4
      Japan JPN-5

Use a StorageClass for encrypted NAS volumes

Caution

A StorageClass for encrypted NAS volumes is available from NAS CSI version 2.0.2 or later.

The NAS CSI driver creates NAS volumes without encryption by default. However, you can create NAS volumes with encryption by specifying encryption in the StorageClass. You can create an encrypted NAS volume using the YAML 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

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

Access a NAS directly from a Pod

If you want to access a NAS directly without using NAS CSI, you can mount it in a Pod using NFS. The example below uses the NFS volume type to mount the NAS server directly. Enter the NAS IP address in the server field and the NAS path in the path field. You can specify the path inside the container using volumeMounts.

Caution

Because NAS-CSI is not used, you must register NAS ACLs manually.

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

Share NAS volumes using SubDir [NAS CSI v2.2.0+]

You can create subdirectories within a single NAS volume, allowing multiple PVCs to share the same NAS volume.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-subdir
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: mount-options
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  server: __NAS_IP__
  share: __NAS_PATH__
  subDir: my-app-data
  deleteOnlySubdir: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-csi-subdir-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi-subdir
---
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-subdir-pvc
  • parameters.subDir: Enter the name of the subdirectory to create.
  • parameters.deleteOnlySubdir: If set to "true", only the subdirectory is deleted when the PVC is deleted, while the NAS volume is retained.
Caution

The # character cannot be used in the parameters.subDir value.

Note

parameters.deleteOnlySubdir is valid only when reclaimPolicy is set to Delete.
To keep both the NAS volume and its subdirectory, set the reclaimPolicy for the StorageClass to Retain.

Create dynamic SubDir using PVC/PV metadata [NAS CSI v2.2.0+]

By using metadata substitution patterns in the parameters.subDir parameter, you can dynamically create subdirectories based on PVC and PV information.
This allows you to create an automatic directory structure based on the namespace and PVC name.

Available substitution patterns

Pattern Description
${pvc.metadata.name} Replaced with the PVC name.
${pvc.metadata.namespace} Replaced with the PVC namespace.
${pv.metadata.name} Replaced with the PV name.

In the example below, if the PVC name is app-data and the namespace is production, the subdirectory is automatically created as production-app-data.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-dynamic-subdir
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: mount-options
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  server: __NAS_IP__
  share: __NAS_PATH__
  subDir: ${pvc.metadata.namespace}-${pvc.metadata.name}
  deleteOnlySubdir: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: app-data
  namespace: production
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  storageClassName: nks-nas-csi-dynamic-subdir
---
kind: Pod
apiVersion: v1
metadata:
  name: my-csi-app
  namespace: production
spec:
  containers:
    - name: my-frontend
      image: busybox
      volumeMounts:
      - mountPath: "/data"
        name: my-volume
      command: [ "sleep", "1000000" ]
  volumes:
    - name: my-volume
      persistentVolumeClaim:
        claimName: app-data
Note

Metadata substitution is performed only once at the time of volume creation. Even if the PVC name or namespace is changed later, the subdirectory name does not change.

Use SubDir in dynamic provisioning [NAS CSI v2.2.0+]

You can specify a subdirectory when dynamically provisioning a NAS volume.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-dynamic-subdir
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: mount-options
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  subDir: ${pvc.metadata.namespace}-${pvc.metadata.name}
  deleteOnlySubdir: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

Separate SubDirs by purpose in static provisioning [NAS CSI v2.2.0+]

You can create multiple subdirectories within an existing NAS volume to separate them by purpose.
Enter the same NAS volume information in server and share of the StorageClass, then create separate StorageClasses with different parameters.subDir values.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-subdir-logs
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: mount-options
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  server: __NAS_IP__
  share: __NAS_PATH__
  subDir: logs
  deleteOnlySubdir: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nks-nas-csi-subdir-config
mountOptions:
- hard
- nolock
- nfsvers=3
provisioner: nas.csi.ncloud.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: mount-options
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  server: __NAS_IP__
  share: __NAS_PATH__
  subDir: config
  deleteOnlySubdir: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

When you specify the StorageClass in each PVC, the logs and config subdirectories are created within the same NAS volume.