|
| 1 | +# OpenEBS LocalPV Hostpath Enable XFS Quota |
| 2 | + |
| 3 | +### Prerequisites |
| 4 | + |
| 5 | +1. A Kubernetes cluster with Kubernetes v1.16 or above is required |
| 6 | +2. All the nodes must have xfs utils installed |
| 7 | +3. The base path used by the provisioner should have XFS filesystem |
| 8 | +4. The base path used by the provisioner should be mounted with XFS project quotas enabled |
| 9 | + |
| 10 | +### Check Basepath |
| 11 | +Verify that filesystem is xfs |
| 12 | +```console |
| 13 | +stat -f -c %T /var/openebs/local |
| 14 | +``` |
| 15 | +Filesystem of Basepath will be shown |
| 16 | +```console |
| 17 | +xfs |
| 18 | +``` |
| 19 | + |
| 20 | +Verify that project quotas are enabled |
| 21 | +```console |
| 22 | +xfs_quota -x -c state | grep 'Project quota state on /var/openebs/local' -A 2 |
| 23 | +``` |
| 24 | +Both Accounting and Enforcement should be ON |
| 25 | +```console |
| 26 | +Project quota state on /var/openebs/local (/dev/loop16) |
| 27 | + Accounting: ON |
| 28 | + Enforcement: ON |
| 29 | +``` |
| 30 | + |
| 31 | +If project quotas are not enabled :- |
| 32 | + |
| 33 | +To set project quota on `/var/openebs/local`, enable project quota on `/var` filesystem, |
| 34 | +edit the `/etc/fstab` file, add `prjquota` after `default` keyword for `/var` file system |
| 35 | +```console |
| 36 | +$ vi /etc/fstab |
| 37 | +………………………………. |
| 38 | +/dev/mapper/Vol-var /var xfs defaults,prjquota 0 0 |
| 39 | +………………………………… |
| 40 | +``` |
| 41 | +Then reboot the system |
| 42 | + |
| 43 | + |
| 44 | +### Installing |
| 45 | +Install the OpenEBS Dynamic LocalPV Provisioner using the following command: |
| 46 | +```console |
| 47 | +kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml |
| 48 | +``` |
| 49 | +Verify that pods in openebs namespace are running |
| 50 | +```console |
| 51 | +$ kubectl get pods -n openebs |
| 52 | + |
| 53 | +NAME READY STATUS RESTARTS AGE |
| 54 | +openebs-localpv-provisioner-6ddbd95d4d-htp7g 1/1 Running 0 7m12s |
| 55 | +openebs-ndm-operator-849d89cb87-djct8 1/1 Running 0 7m12s |
| 56 | +openebs-ndm-zd8lt 1/1 Running 0 7m12s |
| 57 | +``` |
| 58 | + |
| 59 | +### Deployment |
| 60 | + |
| 61 | +#### 1. Create a Storage Class |
| 62 | +```yaml |
| 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 | +provisioner: openebs.io/local |
| 75 | +volumeBindingMode: WaitForFirstConsumer |
| 76 | +reclaimPolicy: Delete |
| 77 | +parameters: |
| 78 | + enableXfsQuota: 'true' |
| 79 | + softLimitGrace: 20% |
| 80 | + hardLimitGrace: 40% |
| 81 | +``` |
| 82 | +`softLimitGrace` and `hardLimitGrace` with PV Storage Request will decide the soft limit and hard limit to be set. |
| 83 | +The size of a limit will be => size of PV Storage request * ( 1 + LimitGrace% ) |
| 84 | +Anyone of hard limit or soft limit can also be used |
| 85 | +[Click here](https://man7.org/linux/man-pages/man8/xfs_quota.8.html#QUOTA_OVERVIEW) for detailed instructions about soft and hard limits. |
| 86 | + |
| 87 | +#### 2. Create a PVC with storage class |
| 88 | +```yaml |
| 89 | +kind: PersistentVolumeClaim |
| 90 | +apiVersion: v1 |
| 91 | +metadata: |
| 92 | + name: local-hostpath-pvc |
| 93 | +spec: |
| 94 | + storageClassName: openebs-hostpath-xfs |
| 95 | + accessModes: |
| 96 | + - ReadWriteOnce |
| 97 | + resources: |
| 98 | + requests: |
| 99 | + storage: 5G |
| 100 | +``` |
| 101 | +The PVC will be in 'Pending' state until the volume is mounted. |
| 102 | +```console |
| 103 | +$ kubectl get pvc |
| 104 | +
|
| 105 | +NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE |
| 106 | +local-hostpath-pvc Pending openebs-hostpath-xfs 21s |
| 107 | +``` |
| 108 | + |
| 109 | +#### 3. Mount the Volume |
| 110 | +Mount the volume to the application pod container. The PVC status will change to 'Bound' when the volume is mounted to a container and quota is applied. A sample BusyBox Pod template is given below. |
| 111 | +```yaml |
| 112 | +apiVersion: v1 |
| 113 | +kind: Pod |
| 114 | +metadata: |
| 115 | + name: busybox |
| 116 | +spec: |
| 117 | + volumes: |
| 118 | + - name: local-storage |
| 119 | + persistentVolumeClaim: |
| 120 | + claimName: local-hostpath-pvc |
| 121 | + containers: |
| 122 | + - name: busybox |
| 123 | + image: busybox |
| 124 | + command: |
| 125 | + - sh |
| 126 | + - -c |
| 127 | + - 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done' |
| 128 | + volumeMounts: |
| 129 | + - mountPath: /mnt/store |
| 130 | + name: local-storage |
| 131 | +``` |
| 132 | +Verify that quota is applied successfully |
| 133 | +```console |
| 134 | +master@node$ sudo xfs_quota -x -c 'report -h' /var/openebs/local/ |
| 135 | +Project quota on /var/openebs/local (/dev/loop16) |
| 136 | + Blocks |
| 137 | +Project ID Used Soft Hard Warn/Grace |
| 138 | +---------- --------------------------------- |
| 139 | +#0 0 0 0 00 [------] |
| 140 | +#1 0 5.7G 6.7G 00 [------] |
| 141 | +``` |
| 142 | +#### Limitation |
| 143 | +* Resize of quota is not supported |
0 commit comments