QuotaPath volumes

更新时间:
复制 MD 格式

You can use the ProjectQuota feature of a file system, such as Ext4, on a local disk to control capacity quotas at the directory level. The Container Storage Interface (CSI) plugin manages the lifecycle of QuotaPath volumes, including creation, quota management, and mounting. This topic describes how to use QuotaPath volumes.

Prerequisites

The Logical Volume Manager (LVM) CSI plugin is deployed. For more information, see Step 2: Deploy the plugin and provisioner components.

Differences among QuotaPath, HostPath, and LVM

HostPath, LVM, and QuotaPath all allow pods to access host storage. Each method has distinct features:

  • HostPath partitions storage by directory. Multiple directories share the space, I/O, and other resources of the same underlying storage device.

  • LVM virtualizes a storage device and then splits it into multiple volumes. Each volume has an independent storage capacity.

  • QuotaPath uses the quota feature of a file system to partition storage by directory. Each directory has an independent storage capacity.

Features

  • Lifecycle management for QuotaPath volumes: automatic creation, deletion, mounting, and unmounting.

  • Expansion for QuotaPath volumes.

  • Node local storage management: automatic operations and maintenance (O&M) for the QuotaPath root directory.

  • Cluster capacity awareness for QuotaPath volumes.

Notes

  • QuotaPath is a local storage type. It is not suitable for high availability (HA) data scenarios.

  • O&M for the QuotaPath root directory and local storage capacity awareness are optional features that are not yet available.

  • If you start a container in privileged mode, the quota limit does not take effect. This behavior is a characteristic of the Ext4 file system.

QuotaPath usage examples

When you use CSI-Provisioner to automatically create a PersistentVolume (PV), note the following:

  • Specify the `rootPath` parameter in the StorageClass.

  • If you want to create the PV on a specific node, add the volume.kubernetes.io/selected-node: nodeName label to the PersistentVolumeClaim (PVC).

  1. Create a StorageClass.

    1. Create a file named alicloud-local-quota.yaml with the following content.

      apiVersion: storage.k8s.io/v1
      kind: StorageClass
      metadata:
        name: alicloud-local-quota
      parameters:
        volumeType: QuotaPath
        rootPath: /mnt/quota
      provisioner: localplugin.csi.alibabacloud.com
      reclaimPolicy: Delete
      allowVolumeExpansion: true
      volumeBindingMode: WaitForFirstConsumer

      Parameter

      Description

      volumeType

      The local storage type. In this example, the storage type is QuotaPath.

      rootPath

      Optional. The name of the directory where the QuotaPath is located.

    2. Run the following command to create the StorageClass.

      kubectl create -f alicloud-local-quota.yaml
  2. Create a PVC.

    1. Create a file named csi-quota.yaml with the following content.

      By default, the CSI plugin uses /mnt/quotapath.namespacex.x as the root directory for QuotaPath. All PVs and their subdirectories are created in this directory.

      To specify a custom parent directory for QuotaPath, add the volume.kubernetes.io/selected-storage: /mnt/xxx annotation to the PVC.

      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: csi-quota
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi
        storageClassName: alicloud-local-quota
    2. Run the following command to create the PVC.

      kubectl create -f csi-quota.yaml
  3. Create an application from a template.

    1. Create a file named web-quota.yaml with the following content.

      apiVersion: v1
      kind: Service
      metadata:
        name: nginx
        labels:
          app: nginx
      spec:
        ports:
        - port: 80
          name: web
        selector:
          app: nginx
      ---
      apiVersion: apps/v1
      kind: StatefulSet
      metadata:
        name: web-quota
      spec:
        selector:
          matchLabels:
            app: nginx
        serviceName: "nginx"
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx
              volumeMounts:
              - name: disk-ssd
                mountPath: /data
            volumes:
              - name: "disk-ssd"
                persistentVolumeClaim:
                  claimName: csi-quota
    2. Run the following command to create the application.

      kubectl create -f web-quota.yaml
  4. Check the application status.

    Run the following command to view the pod information.

    kubectl get pod |grep quota

    Expected output:

    NAME          READY   STATUS    RESTARTS   AGE
    web-quota-0   1/1     Running   0          16s

    Run the following command to view the PVC information.

    kubectl get pvc

    Expected output:

    NAME        STATUS   VOLUME                CAPACITY   ACCESS MODES   STORAGECLASS           AGE
    csi-quota   Bound    local-f4b129a5-****   2Gi        RWO            alicloud-local-quota   48s

    Run the following command to view the PV information.

    kubectl get pv |grep quota

    Expected output:

    NAME                  CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM               STORAGECLASS           REASON   AGE
    local-f4b129a5-****   2Gi        RWO            Delete           Bound    default/csi-quota   alicloud-local-quota            66s

    Run the following commands to view the pod mount details.

    kubectl exec -ti web-quota-0 sh
    df |grep data

    Expected output:

    Filesystem  1K-blocks  Used Available Use% Mounted on
    /dev/vdd    2097152       4   2097148   1% /data

    Run the following command to list the directories in /data.

    ls /data

    Expected output:

    lost+found

    Run the following commands to create and view a test directory in /data.

    touch /data/test
    ls /data

    Expected output:

    lost+found test
  5. Expand the volume.

    Run the following command to view the PVC information.

    kubectl get pvc

    Expected output:

    NAME        STATUS   VOLUME                CAPACITY   ACCESS MODES   STORAGECLASS           AGE
    csi-quota   Bound    local-f4b129a5-****   2Gi        RWO            alicloud-local-quota   42s

    Run the following command to expand the PVC to 3 GiB.

    kubectl patch pvc csi-quota -p '{"spec":{"resources":{"requests":{"storage":"3Gi"}}}}'

    Expected output:

    persistentvolumeclaim/csi-quota patched

    Run the following command to view the PVC information.

    kubectl get pvc

    Expected output:

    NAME        STATUS   VOLUME                CAPACITY   ACCESS MODES   STORAGECLASS           AGE
    csi-quota   Bound    local-f4b129a5-****   3Gi        RWO            alicloud-local-quota   4m30s

    Run the following commands to verify that the volume is expanded to 3 GiB.

    kubectl exec -ti web-quota-0 sh
    df |grep data

    Expected output:

    Filesystem  1K-blocks  Used Available Use% Mounted on
    /dev/vdd    3145728       4   3145724   1% /data