XFS Quota

Explore this Page

Overview

To enforce storage limits, it is essential to enable and properly configure XFS project quotas. This document outlines the necessary prerequisites, installation procedures, filesystem configurations, and StorageClass setup required to enable XFS quotas.

Additionally, it describes how to create Persistent Volume Claims (PVCs), verify quota enforcement, and adjust quota limits when necessary.

By following the steps in this document, you will be able to successfully enable, configure, and manage XFS Quotas for deployments across various Linux distributions, including Ubuntu, Debian, RHEL, CentOS, and Fedora.

Requirements

To use XFS Quotas with Local PV Hostpath, ensure the following requirements are fulfilled:

  • Install the xfsprogs package.
  • Confirm that the filesystem type is XFS.
  • Configure the filesystem to use the pquota or prjquota mount option.

Installing the xfsprogs Package

For Ubuntu/Debian Systems

Copy
Install xfsprogs on Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y xfsprogs

For RHEL/CentOS Systems

Copy
Install xfsprogs on RHEL/CentOS
sudo yum install -y xfsprogs

For Fedora Systems

Copy
Install xfsprogs on Fedora
sudo dnf install -y xfsprogs

Mounting the Filesystem with pquota Option

Verifying Filesystem Type

Check if the hostPath directory (/var/openebs/local by default) is using the XFS filesystem:

Copy
Check the filesystem type
df -Th /var/openebs/local
Copy
Sample Output
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/nvme0n1p1 xfs   8.0G  959M  7.1G  12% /

If the directory does not exist yet, use the following script to determine the base directory and filesystem:

Copy
Script to find base path and filesystem
BASEPATH="/var/openebs/local"
until OUTPUT=$(df -Th $BASEPATH 2> /dev/null)
do
  BASEPATH=$(echo "$BASEPATH" | sed 's|\(.*\)/.*|\1|')
done
echo "PATH=${BASEPATH}"
echo "$OUTPUT"

Checking Existing Mount Options

Verify whether the mount options for the device include pquota or prjquota:

Copy
Check Mount Options for the Device
sudo mount | grep "^/dev/nvme0n1p1"
Copy
Sample Output
/dev/nvme0n1p1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

If the mount options already include pquota or prjquota, you can proceed to the next section. If not, continue with Mounting the Device with pquota.

Mounting the Device with pquota

Root Filesystem

If the filesystem is mounted as the root (/), follow these steps:

  1. Edit the GRUB configuration.

    Copy
    Open /etc/default/grub
    sudo vi /etc/default/grub
  2. Locate the GRUB_CMDLINE_LINUX entry and append rootflags=pquota.

    Copy
    Locate GRUB_CMDLINE_LINUX Entry
    GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto net.ifnames=0 console=ttyS0 rootflags=pquota"
  3. Identify the GRUB configuration file path.

    Copy
    Possible Locations
    /boot/grub2/grub.cfg
    /boot/efi/EFI/ubuntu/grub.cfg
    /boot/efi/EFI/debian/grub.cfg
    /boot/efi/EFI/redhat/grub.cfg
    /boot/efi/EFI/centos/grub.cfg
    /boot/efi/EFI/fedora/grub.cfg
  4. Backup the existing GRUB configuration.

    Copy
    Backup Existing GRUB File
    sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup
  5. Regenerate the GRUB configuration.

    Copy
    Generate Updated GRUB Configuration
    sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  6. Reboot the system.

    Copy
    Reboot System
    sudo reboot
  7. After reboot, verify the mount options again.

    Copy
    Check Mount Options
    sudo mount | grep "^/dev/nvme0n1p1"
    Copy
    Sample Output
    /dev/nvme0n1p1 on / type xfs (rw,relatime,seclabel,attr2,inode64,prjquota)

Filesystem on a Data Disk

If the filesystem is on a data disk:

  1. Unmount the device.

    Copy
    Unmount the Device (Replace with Your Device)
    sudo umount /dev/nvme1n1
  2. Mount the device with the pquota option.

    Copy
    Mount the Device with pquota
    sudo mount -o rw,pquota /dev/nvme1n1 /mnt/data

    pquota cannot be enabled using a remount operation.

  3. Verify the mount options.

    Copy
    Verify pquota Mount Option
    sudo mount | grep "^/dev/nvme1n1"
  4. Update /etc/fstab to persist the change.

    Copy
    Add pquota Option to /etc/fstab File
    UUID=9cff3d69-3769-4ad9-8460-9c54050583f9 /mnt/data xfs defaults,pquota 0 0

Enabling XFS Quota

Creating a StorageClass

Define a StorageClass with XFS quota support.

Copy
StorageClass enabling XFS Quota
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: puls8-hostpath-xfs
  annotations:
    openebs.io/cas-type: local
    cas.openebs.io/config: |
      - name: StorageType
        value: "hostpath"
      - name: BasePath
        value: "/var/openebs/local/"
      - name: XFSQuota
        enabled: "true"
provisioner: openebs.io/local
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

Advanced XFS Quota Configuration

Configure softLimitGrace and hardLimitGrace.

Copy
StorageClass with XFS Quota Advanced Options
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: puls8-hostpath-xfs
  annotations:
    openebs.io/cas-type: local
    cas.openebs.io/config: |
      - name: StorageType
        value: "hostpath"
      - name: BasePath
        value: "/var/openebs/local/"
      - name: XFSQuota
        enabled: "true"
        data:
          softLimitGrace: "0%"
          hardLimitGrace: "0%"
provisioner: openebs.io/local
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

If no values are specified, defaults are softLimitGrace: "0%" and hardLimitGrace: "0%", restricting volume size to the PVC's requested storage.

Creating a PVC

Create a PVC using the StorageClass name.

Copy
PVC using XFS Quota StorageClass
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: local-hostpath-xfs
spec:
  storageClassName: puls8-hostpath-xfs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Check the status of the PVC.

Copy
Verify PVC Status
kubectl get pvc
Copy
Sample Output
NAME                  STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS           AGE
local-hostpath-xfs    Pending                                      puls8-hostpath-xfs   21s

Mounting the Volume

Mount the volume to the application pod container.

Copy
Sample Pod Mounting the Volume
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  volumes:
  - name: local-storage
    persistentVolumeClaim:
      claimName: local-hostpath-xfs
  containers:
  - name: busybox
    image: busybox
    command:
      - sh
      - -c
      - 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done'
    volumeMounts:
    - mountPath: /mnt/store
      name: local-storage

Verify that the XFS project quota is enforced.

Copy
Check XFS Quota Report
sudo xfs_quota -x -c 'report -h' /var/openebs/local/
Copy
Sample Output
Project quota on /var/openebs/local (/dev/loop16)
                        Blocks
Project ID   Used   Soft   Hard Warn/Grace
---------- ---------------------------------
#0              0      0      0  00 [------]
#1              0   5.7G   6.7G  00 [------]

Managing and Modifying XFS Quota

Identifying the BasePath Directory

Retrieve the BasePath directory.

Copy
Get BasePath from StorageClass
kubectl describe sc <storageclass-name>

Locating the Node

Identify the node where the volume exists.

Copy
Get PVC Details
kubectl get pvc --namespace <namespace>
Copy
Describe PV to find Node and Path
kubectl describe pv <pv-name>

Find the node.

Copy
Get Node Information
kubectl get node -l 'kubernetes.io/hostname in (node-name)'

Modifying the XFS Quota Limits

Changing Quota Limits

Retrieve the current quota report.

Copy
Get Current Quota Report
sudo xfs_quota -x -c 'report -h' /var/openebs/local
Copy
Sample Output
Project quota on /var/openebs/local (/dev/nvme1n1)
                        Blocks
Project ID   Used   Soft   Hard Warn/Grace
---------- ---------------------------------
#0           0      0      0   00 [------]
#1           1G     2.0G   2.0G 00 [------]

Modify the soft and hard limits.

Copy
Modify Quota Limits
sudo xfs_quota -x -c 'limit -p bsoft=3G bhard=5G 1' /var/openebs/local

Verify the updated limits.

Copy
Verify Updated Quota Limits
sudo xfs_quota -x -c 'report -h' /var/openebs/local
Copy
Sample Output
Project quota on /var/openebs/local (/dev/nvme1n1)
                        Blocks              
Project ID   Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
#0              0      0      0  00 [------]
#1             1G     3G     5G  00 [------]

Limitations

Quota resizing is not supported: If you need to adjust quotas, you must manually modify the soft and hard limits as shown above.

Learn More