|
| 1 | +--- |
| 2 | +id: enable-xfs-quota |
| 3 | +title: Enable XFS Quota on LocalPV Hostpath |
| 4 | +keywords: |
| 5 | + - OpenEBS LocalPV Hostpath Enable XFS Quota |
| 6 | + - XFS Quota |
| 7 | + - Enable XFS Quota |
| 8 | + - Advanced Operations |
| 9 | +description: This section talks about enabling XFS quotas for OpenEBS LocalPV Hostpath. |
| 10 | +--- |
| 11 | + |
| 12 | +# Enable XFS Quota on LocalPV Hostpath |
| 13 | + |
| 14 | +This document provides the necessary steps to enable and configure XFS Quota on OpenEBS LocalPV HostPath. By following these instructions, you will install the OpenEBS LocalPV provisioner, create a StorageClass with XFS Quota support, and set up a PersistentVolumeClaim (PVC) to apply project quotas on the local volumes. It also includes the process for mounting the volume to an application pod and verifying that the quota is successfully applied. |
| 15 | + |
| 16 | +## Install the OpenEBS Dynamic LocalPV Provisioner |
| 17 | + |
| 18 | +1. To install the OpenEBS LocalPV Hostpath Provisioner, execute the following command: |
| 19 | + |
| 20 | +``` |
| 21 | +kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml |
| 22 | +``` |
| 23 | + |
| 24 | +2. Verify the pods in the `openebs` namespace are running. |
| 25 | + |
| 26 | +``` |
| 27 | +kubectl get pods -n openebs |
| 28 | +``` |
| 29 | + |
| 30 | +**Example Output** |
| 31 | + |
| 32 | +``` |
| 33 | +NAME READY STATUS RESTARTS AGE |
| 34 | +openebs-localpv-provisioner-6ddbd95d4d-htp7g 1/1 Running 0 7m12s |
| 35 | +``` |
| 36 | + |
| 37 | +## Create StorageClass |
| 38 | + |
| 39 | +1. To create a hostpath StorageClass with the XFSQuota configuration option, use the following YAML definition. This configuration will enable the XFSQuota for the specified path and storage type. |
| 40 | + |
| 41 | +``` |
| 42 | +apiVersion: storage.k8s.io/v1 |
| 43 | +kind: StorageClass |
| 44 | +metadata: |
| 45 | + name: openebs-hostpath-xfs |
| 46 | + annotations: |
| 47 | + openebs.io/cas-type: local |
| 48 | + cas.openebs.io/config: | |
| 49 | + - name: StorageType |
| 50 | + value: "hostpath" |
| 51 | + - name: BasePath |
| 52 | + value: "/var/openebs/local/" |
| 53 | + - name: XFSQuota |
| 54 | + enabled: "true" |
| 55 | +provisioner: openebs.io/local |
| 56 | +volumeBindingMode: WaitForFirstConsumer |
| 57 | +reclaimPolicy: Delete |
| 58 | +``` |
| 59 | + |
| 60 | +2. For advanced configuration of XFSQuota, you may also set the `softLimitGrace` and `hardLimitGrace` parameters, which define the storage capacity limits beyond the Persistent Volume (PV) storage request. The updated YAML definition is as follows: |
| 61 | + |
| 62 | +``` |
| 63 | +apiVersion: storage.k8s.io/v1 |
| 64 | +kind: StorageClass |
| 65 | +metadata: |
| 66 | + name: openebs-hostpath-xfs |
| 67 | + annotations: |
| 68 | + openebs.io/cas-type: local |
| 69 | + cas.openebs.io/config: | |
| 70 | + - name: StorageType |
| 71 | + value: "hostpath" |
| 72 | + - name: BasePath |
| 73 | + value: "/var/openebs/local/" |
| 74 | + - name: XFSQuota |
| 75 | + enabled: "true" |
| 76 | + data: |
| 77 | + softLimitGrace: "0%" |
| 78 | + hardLimitGrace: "0%" |
| 79 | +provisioner: openebs.io/local |
| 80 | +volumeBindingMode: WaitForFirstConsumer |
| 81 | +reclaimPolicy: Delete |
| 82 | +``` |
| 83 | + |
| 84 | +:::note |
| 85 | +- `softLimitGrace` and `hardLimitGrace` are used in conjunction with the PV storage request to determine the soft and hard limits of the quota. |
| 86 | + |
| 87 | +- The size of these limits is calculated as **"Size of PV storage request * (1 + LimitGrace%)"** |
| 88 | + |
| 89 | +- If no values are specified, the default is **softLimitGrace: "0%" / hardLimitGrace: "0%"**, meaning the storage capacity is limited to the PV storage request value. |
| 90 | + |
| 91 | + For example, with a PV of 100Gi capacity and values **softLimitGrace: "90%" / hardLimitGrace: "100%"**, the soft limit will be set to 190Gi, and the hard limit will be set to 200Gi. |
| 92 | + You can select to use either `softLimitGrace` or `hardLimitGrace` independently based on your requirements. |
| 93 | + |
| 94 | + Refer to the relevant [xfs_quota documentation](https://man7.org/linux/man-pages/man8/xfs_quota.8.html#QUOTA_OVERVIEW) for more detailed instructions regarding the configuration of soft and hard limits. |
| 95 | +::: |
| 96 | + |
| 97 | +## Create a PVC |
| 98 | + |
| 99 | +1. To create a PVC using the StorageClass's name, use the following definition: |
| 100 | + |
| 101 | +``` |
| 102 | +kind: PersistentVolumeClaim |
| 103 | +apiVersion: v1 |
| 104 | +metadata: |
| 105 | + name: local-hostpath-xfs |
| 106 | +spec: |
| 107 | + storageClassName: openebs-hostpath-xfs |
| 108 | + accessModes: |
| 109 | + - ReadWriteOnce |
| 110 | + resources: |
| 111 | + requests: |
| 112 | + storage: 5Gi |
| 113 | +``` |
| 114 | + |
| 115 | +At this stage, the PVC will remain in the 'Pending' state until the volume is successfully mounted. |
| 116 | + |
| 117 | +2. Verify the PVC status. |
| 118 | + |
| 119 | +``` |
| 120 | +$ kubectl get pvc |
| 121 | +``` |
| 122 | + |
| 123 | +**Example Output** |
| 124 | + |
| 125 | +``` |
| 126 | +NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE |
| 127 | +local-hostpath-xfs Pending openebs-hostpath-xfs 21s |
| 128 | +``` |
| 129 | + |
| 130 | +## Mount the Volume |
| 131 | + |
| 132 | +1. Mount the volume to the application pod container. A sample BusyBox Pod template is as follows: |
| 133 | + |
| 134 | +``` |
| 135 | +apiVersion: v1 |
| 136 | +kind: Pod |
| 137 | +metadata: |
| 138 | + name: busybox |
| 139 | +spec: |
| 140 | + volumes: |
| 141 | + - name: local-storage |
| 142 | + persistentVolumeClaim: |
| 143 | + claimName: local-hostpath-xfs |
| 144 | + containers: |
| 145 | + - name: busybox |
| 146 | + image: busybox |
| 147 | + command: |
| 148 | + - sh |
| 149 | + - -c |
| 150 | + - 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done' |
| 151 | + volumeMounts: |
| 152 | + - mountPath: /mnt/store |
| 153 | + name: local-storage |
| 154 | +``` |
| 155 | + |
| 156 | +The PVC status will change to 'Bound' once the volume is successfully mounted and the quota will be applied. |
| 157 | + |
| 158 | +2. Verify that the XFS project quota is applied. |
| 159 | + |
| 160 | +``` |
| 161 | +$ sudo xfs_quota -x -c 'report -h' /var/openebs/local/ |
| 162 | +``` |
| 163 | + |
| 164 | +**Example Output** |
| 165 | + |
| 166 | +``` |
| 167 | +Project quota on /var/openebs/local (/dev/loop16) |
| 168 | + Blocks |
| 169 | +Project ID Used Soft Hard Warn/Grace |
| 170 | +---------- --------------------------------- |
| 171 | +#0 0 0 0 00 [------] |
| 172 | +#1 0 5.7G 6.7G 00 [------] |
| 173 | +``` |
| 174 | + |
| 175 | +## Limitation |
| 176 | + |
| 177 | +Resizing of quota is not supported. |
| 178 | + |
| 179 | +## See Also |
| 180 | + |
| 181 | +- [XFS Quota Prerequisites](xfs-quota-pre.md) |
| 182 | +- [Modify XFS Quota on LocalPV Hostpath](modify-xfs-quota.md) |
| 183 | +- [XFS Quota with Loop Device](xfs-quota-pre.md) |
0 commit comments