Complex access paths and high latency in traditional storage solutions often degrade I/O performance. Directly mounting a Network Attached Storage (NAS) file system in a sandboxed container optimizes the storage path, enabling containers to read from and write to the NAS file system directly for significantly improved performance. This topic explains how this direct mounting works and shows you how to implement it.
Background information
Virtio-fs is a shared file system that enables resources such as Volumes, Secrets, and ConfigMaps to be shared with a virtual machine's guest operating system. This setup allows NAS file systems to be natively mounted via a Volume.
However, in this setup, the NAS is mounted on the host node. When containers access the NAS, their I/O must pass through virtio-fs to reach the host-mounted file system, which introduces performance overhead.
Sandboxed containers support direct mounting of NAS file systems. To achieve this, the system unmounts the NAS mount target from the host, mounts the NAS file system inside the guest operating system, then bind-mounts it into the container. This process allows the container to read from and write to the NAS file system directly, providing near-native performance.
How it works
The direct mount process for a NAS file system in a sandboxed container is as follows:
The Kubelet requests the CSI-Plugin to mount the NAS Volume.
The CSI-Plugin mounts the NAS file system on the host.
The Kubelet requests the Kangaroo-Runtime to create the container.
The Kangaroo-Runtime parses the NAS mount information, passes it to the guest operating system, and simultaneously unmounts the NAS file system from the host.
The Kangaroo-Runtime requests the Agent to create the container.
The Agent mounts the NAS file system inside the guest operating system.
The Agent bind-mounts the NAS file system from the guest operating system into the container.
Prerequisites
Create a NAS file system, and obtain the mount target information of the NAS file system.
ImportantThe NAS file system and the ACK cluster must be in the same Virtual Private Cloud (VPC).
Procedure
Create a statically provisioned PersistentVolume (PV).
Save the following YAML as
nas-pv-csi.yaml.apiVersion: v1 kind: PersistentVolume metadata: labels: alicloud-pvname: nas-pv-csi name: nas-pv-csi spec: accessModes: - ReadWriteMany capacity: storage: 5Gi csi: driver: nasplugin.csi.alibabacloud.com volumeAttributes: options: noresvport,nolock path: /csi server: ${nas-server-address} # Replace with your actual NAS mount target address. # Format: file-system-id.region.nas.aliyuncs.com # To get it: 1) Go to the NAS Console > File Systems. # 2) Select your file system, go to "Mount Targets" tab. # 3) Copy the "Mount Target Domain Name". vers: "3" volumeHandle: nas-pv-csi persistentVolumeReclaimPolicy: RetainRun the following command to create the statically provisioned PV.
kubectl create -f nas-pv-csi.yaml
Create a PersistentVolumeClaim (PVC) for the NAS storage. Use
selector.matchLabelsto bind the PVC to the PV by its label.Save the following YAML as
nas-pvc-csi.yaml.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nas-pvc-csi namespace: default spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: nas-pv-csiRun the following command to create the PVC.
kubectl create -f nas-pvc-csi.yaml
Create an application and mount the PVC.
Save the following YAML as
deploy-nas-csi.yaml.apiVersion: apps/v1 kind: Deployment metadata: name: deploy-nas-csi spec: replicas: 2 selector: matchLabels: app: busybox template: metadata: labels: app: busybox annotations: storage.alibabacloud.com/enable_nas_passthrough: "true" spec: runtimeClassName: runv containers: - name: busybox image: registry.cn-hangzhou.aliyuncs.com/acs/busybox:v1.29.2 command: - tail - -f - /dev/null volumeMounts: - name: nas-pvc mountPath: "/data" restartPolicy: Always volumes: - name: nas-pvc persistentVolumeClaim: claimName: nas-pvc-csi #Must match the PVC name created in the previous step to bind the PVC.Direct NAS mounting is disabled for pods by default. To enable the NAS passthrough feature, add the following annotation to the pod template:
annotations: storage.alibabacloud.com/enable_nas_passthrough: "true"Run the following command to create the application.
kubectl create -f deploy-nas-csi.yaml
Verify the mount.
Run the following command to view pod information.
kubectl get podsExpected output:
NAME READY STATUS RESTARTS AGE deploy-nas-csi-847f8b****-qmv2m 1/1 Running 0 47s deploy-nas-csi-847f8b****-wj8k5 1/1 Running 0 47sRun the following command to open a shell in the specified pod.
kubectl exec -it deploy-nas-csi-847f8b****-qmv2m -- shRun the following command to view the mount information.
mountIf the output contains an entry for the
/datamount point, the mount is successful. A successful mount produces output similar to the following: