You can use the project quota feature of file systems on local disks, such as the
Ext4 file system. The project quota feature allows you to control the disk quota at
the directory level. You can also use the CSI plug-in to manage the lifecycle of QuotaPath
volumes, such as division, quota limit, and mounting of QuotaPath volumes. This topic
describes how to use QuotaPath volumes.
Differences among QuotaPath volumes, hostPath volumes, and LVs
To enable pods to use the storage of nodes, you can use hostPath volumes, LVs, and
QuotaPath volumes. However, each type of volume has the following limits:
- hostPath volumes share a directory which can be divided into multiple subdirectories.
The subdirectories share the space and I/O of the same disk.
- Logical Volume Manager (LVM) virtualizes the disk and divides the disk into multiple
volumes. Each volume has an independent storage quota.
- The QuotaPath volume uses the quota feature of file systems. This feature allows you
to divide the directory into multiple directories. Each directory has an independent
storage quota.
Features
- Lifecycle management of QuotaPath volumes: automatic creation, deletion, mounting,
and unmounting.
- Expansion of QuotaPath volumes.
- Automatic operations and maintenance of root directories where QuotaPath volumes are
mounted. This enables you to manage the local storage of nodes.
- Storage usage monitoring for clusters that use QuotaPath volumes.
Precautions
- QuotaPath volumes are not applicable to scenarios where the high availability of data
must be guaranteed.
- The features of automatic operations and maintenance of root directories and storage
usage monitoring for clusters that use QuotaPath volumes are not supported in current
versions.
- If you run a pod as the root user in privileged mode, the project quota feature of
file systems on local disks, such as the Ext4 file system, does not take effect.
Examples
When you use CSI-Provisioner to create persistent volumes (PVs), take note of the
following limits:
- You must specify the name of the rootPath in a StorageClass.
- If you want to create a PV on a specified node, you must add the volume.kubernetes.io/selected-node: nodeName label to the related PVC.
- Create a StorageClass.
- Create a file named alicloud-local-quota.yaml and copy the following content to the file:
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 type of volume. The volume type is set to QuotaPath in this example. |
rootPath |
Specifies the name of the directory where the QuotaPath volume is mounted. |
- Run the following command to create a StorageClass:
kubectl create -f alicloud-local-quota.yaml
- Create a persistent volume claim (PVC).
- Create a file named csi-quota.yaml and copy the following content to the file:
By default, the CSI plug-in uses /mnt/quotapath.namespacex.x as the root directory of QuotaPath volumes. All PVs are mounted to subdirectories
in this root directory.
You can add the following annotation to the PVC to define the parent directory of
the QuotaPath volume: volume.kubernetes.io/selected-storage: /mnt/xxx.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-quota
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: alicloud-local-quota
- Run the following command to create a PVC:
kubectl create -f csi-quota.yaml
- Use the following template to create an application:
- Create a file named web-quota.yaml file and copy the following content to the file:
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
- Run the following commands to create an application:
kubectl create -f web-quota.yaml
- Query the status of the application.
Run the following command to query the pod that runs the application:
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 query 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 query 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 command to query the storage information about the LV that is mounted
to the /data directory of the pod:
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 query all directories in the
/data directory:
ls /data
Expected output:
lost+found
Run the following command to create a directory named test in the
/data directory:
touch /data/test
ls /data
Expected output:
lost+found test
- Expand the QuotaPath volume.
Run the following command to query 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 query 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 command to check whether the QuotaPath 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