You can use the CSI plug-in to mount a cloud disk to a sandboxed container. This significantly improves I/O performance. This topic describes how to use the CSI plug-in to directly mount a cloud disk to a sandboxed container and provides an example to demonstrate the procedure. A cloud disk can also be mounted to a container through the host or the 9pfs file system. This topic compares the I/O performance in these mount modes.

Background information

You can mount cloud disks to sandboxed containers by using the CSI plug-in. In the community solution, a cloud disk is first mounted to the host, formatted, and then mounted to a local directory. Then, this local directory is shared to a container through 9pfs. However, 9pds significantly degrades the I/O performance of containers. To improve the I/O performance, Alibaba Cloud Container Service for Kubernetes (ACK) allows you to directly mount cloud disks to sandboxed containers by using the CSI plug-in. This feature allows you to mount a cloud disk to a container after the container is started. Previously, you can mount a cloud disk to only the host and only before the container is started. This improves the I/O performance because 9pfs is no longer required for a container to access a cloud disk.
Notice You cannot directly mount cloud disks to nodes use Sandboxed-Container V2.
Starting from Sandboxed-Container V1.1.0, ACK automatically enables this feature for all sandboxed containers.
Figure 1. Comparison between the community solution and ACK solution to mount cloud disks and Network Attached Storage (NAS) file systems
Solutions to mount disks and NAS file systems to containers

How the direct mount solution works

How the direct mount solution works

The following table describes how to use the CSI plug-in to mount a cloud disk to a sandboxed container.

Step Description
The kubelet requests the CSI plug-in to mount a cloud disk.
The CSI plug-in sends a request to QueryServer to query whether a mounted volume that corresponds to the cloud disk exists. QueryServer is a local database that stores information about mounted volumes.
If no such mounted volume is found, information about the disk, such as the mount target and mount directory, is written to QueryServer and then the corresponding cloud disk is formatted and ready to use.
When a pod is ready, the kubelet starts to create a container. The request to mount the cloud disk is eventually forwarded to Kata-Runtime.
Kata-Runtime sends a request to QueryServer to query information about the cloud disk. This includes the mount target and mount directory.
Kata-Runtime sends a request to Kata-Agent.
Kata-Agent starts a container and mounts the cloud disk to the container.

Examples

The following example describes how to mount a cloud disk to a sandboxed container. In this example, a YAML file template is used to create resource objects.

  1. Use the following template to create resource objects:
    cat <<EOF | kubectl create -f -
    allowVolumeExpansion: true
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alicloud-disk-ssd
    parameters:
      type: cloud_ssd
    provisioner: diskplugin.csi.alibabacloud.com
    reclaimPolicy: Delete
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: disk-pvc-01
      namespace: default
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 25Gi
      storageClassName: alicloud-disk-ssd
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: busybox
      name: busybox
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: busybox
      template:
        metadata:
          labels:
            app: busybox
        spec:
          containers:
            - name: busybox
              image: registry.cn-hangzhou.aliyuncs.com/acs/busybox:v1.29.2
              command:
              - tail
              - -f
              - /dev/null
              volumeMounts:
                - mountPath: "/data"
                  name: disk-pvc
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          runtimeClassName: runv
          volumes:
            - name: disk-pvc
              persistentVolumeClaim:
                claimName: disk-pvc-01
    EOF
  2. Run the following commands to check the type of file system that is mounted to the pod:
    kubectl get pods
    kubectl exec -it ${podid} sh
    mount | grep /data | grep -vi 9p
    If the mount point type is not 9pfs, it indicates that the cloud disk is mounted to the container.

Comparison in I/O performance

  • Input/output operations per second (IOPS) of random reads

    Mount mode Result
    Host read: IOPS=2571, BW=10.0MiB/s (10.5MB/s)(604MiB/60094msec)
    CSI plug-in read: IOPS=2571, BW=10.0MiB/s (10.5MB/s)(603MiB/60006msec)
    9PFS read: IOPS=2558, BW=9.99MiB/s (10.5MB/s)(600MiB/60001msec)
  • IOPS of random writes

    Mount mode Result
    Host write: IOPS=2481, BW=9926KiB/s (10.2MB/s)(582MiB/60011msec)
    CSI plug-in write: IOPS=2481, BW=9926KiB/s (10.2MB/s)(582MiB/60005msec)
    9PFS write: IOPS=1280, BW=5123KiB/s (5246kB/s)(300MiB/60001msec)
  • Throughput of random reads

    Mount mode Result
    Host read: IOPS=133, BW=133MiB/s (140MB/s)(8110MiB/60926msec)
    CSI plug-in read: IOPS=133, BW=133MiB/s (140MB/s)(8052MiB/60514msec)
    9PFS read: IOPS=10, BW=10.0MiB/s (10.5MB/s)(603MiB/60079msec)
  • Throughput of random writes

    Mount mode Result
    Host write: IOPS=130, BW=130MiB/s (137MB/s)(7854MiB/60251msec)
    CSI plug-in write: IOPS=130, BW=131MiB/s (137MB/s)(7907MiB/60370msec)
    9PFS write: IOPS=5, BW=5123KiB/s (5246kB/s)(301MiB/60159msec)
Notice To improve the I/O performance of 9pfs, qemu cache is automatically enabled on sandboxed containers. The preceding results are recorded when qemu cache is disabled.

The preceding results show that the throughput and IOPS are almost the same between a cloud disk that is mounted through the host and a cloud disk that is mounted by using CSI. The random read IOPS is rather close between a cloud disk that is mounted through 9pfs and a cloud disk that is mounted by using CSI. However, a cloud disk that is mounted by using CSI has significant advantages in other I/O scenarios.