From 3fd037200d28f601a432f8de029c071258ef5c57 Mon Sep 17 00:00:00 2001 From: Namburi Soujanya <54130357+soujanyanmbri@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:31:59 +0530 Subject: [PATCH] Make storage provisions configurable. (#263) Persistent volume helm configuration --- .github/workflows/pr-build.yml | 2 +- .../helm/templates/mongodb/statefulset.yaml | 3 +- deploy/helm/templates/mongodb/storage.yaml | 34 +++++++++---- .../helm/templates/postgres/statefulset.yaml | 2 +- deploy/helm/templates/postgres/storage.yaml | 33 +++++++++---- deploy/helm/values-pv.yaml | 37 ++++++++++++++ deploy/helm/values.yaml | 48 +++++++++++++------ docs/setup.md | 11 ++++- docs/troubleshooting.md | 13 +++++ 9 files changed, 149 insertions(+), 34 deletions(-) create mode 100644 deploy/helm/values-pv.yaml diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 6bbc533b..1513ff0f 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -259,4 +259,4 @@ jobs: run: | cd services/web npm install - npm run lint + npm run lint \ No newline at end of file diff --git a/deploy/helm/templates/mongodb/statefulset.yaml b/deploy/helm/templates/mongodb/statefulset.yaml index da60b6c6..9d13689d 100644 --- a/deploy/helm/templates/mongodb/statefulset.yaml +++ b/deploy/helm/templates/mongodb/statefulset.yaml @@ -34,4 +34,5 @@ spec: volumes: - name: mongodb-data persistentVolumeClaim: - claimName: {{ .Values.mongodb.pvc.name }} + claimName: {{ .Values.mongodb.storage.pvc.name }} + \ No newline at end of file diff --git a/deploy/helm/templates/mongodb/storage.yaml b/deploy/helm/templates/mongodb/storage.yaml index 759d215a..ea7b61c6 100644 --- a/deploy/helm/templates/mongodb/storage.yaml +++ b/deploy/helm/templates/mongodb/storage.yaml @@ -1,16 +1,34 @@ -kind: PersistentVolumeClaim +{{- if eq .Values.mongodb.storage.type "manual" }} apiVersion: v1 - +kind: PersistentVolume +metadata: + name: {{ .Values.mongodb.storage.pv.name }} + labels: + release: {{ .Release.Name }} + {{- toYaml .Values.mongodb.storage.pv.labels | nindent 4 }} +spec: + storageClassName: {{ .Values.mongodb.storage.type }} + capacity: + storage: {{ .Values.mongodb.storage.pv.resources.storage }} + accessModes: + - ReadWriteOnce + hostPath: + path: {{ .Values.mongodb.storage.pv.hostPath }} +--- +{{- end }} +apiVersion: v1 +kind: PersistentVolumeClaim metadata: - name: {{ .Values.mongodb.pvc.name }} + name: {{ .Values.mongodb.storage.pvc.name }} labels: release: {{ .Release.Name }} - {{- toYaml .Values.mongodb.pvc.labels | nindent 4 }} - + {{- toYaml .Values.mongodb.storage.pvc.labels | nindent 4 }} spec: - #storageClassName: local-path + {{- if ne .Values.mongodb.storage.type "default" }} + storageClassName: {{ .Values.mongodb.storage.type }} + {{- end }} accessModes: - ReadWriteOnce - resources: - {{- toYaml .Values.mongodb.pvc.resources | nindent 4 }} + {{- toYaml .Values.mongodb.storage.pvc.resources | nindent 4 }} + diff --git a/deploy/helm/templates/postgres/statefulset.yaml b/deploy/helm/templates/postgres/statefulset.yaml index 46d6602d..e0356001 100644 --- a/deploy/helm/templates/postgres/statefulset.yaml +++ b/deploy/helm/templates/postgres/statefulset.yaml @@ -37,4 +37,4 @@ spec: volumes: - name: postgres-data persistentVolumeClaim: - claimName: {{ .Values.postgresdb.pvc.name }} + claimName: {{ .Values.postgresdb.storage.pvc.name }} diff --git a/deploy/helm/templates/postgres/storage.yaml b/deploy/helm/templates/postgres/storage.yaml index 17afb462..6d50bbbd 100644 --- a/deploy/helm/templates/postgres/storage.yaml +++ b/deploy/helm/templates/postgres/storage.yaml @@ -1,16 +1,33 @@ -kind: PersistentVolumeClaim +{{- if eq .Values.postgresdb.storage.type "manual" }} apiVersion: v1 - +kind: PersistentVolume +metadata: + name: {{ .Values.postgresdb.storage.pv.name }} + labels: + release: {{ .Release.Name }} + {{- toYaml .Values.postgresdb.storage.pv.labels | nindent 4 }} +spec: + storageClassName: {{ .Values.postgresdb.storage.type }} + capacity: + storage: {{ .Values.postgresdb.storage.pv.resources.storage }} + accessModes: + - ReadWriteOnce + hostPath: + path: {{ .Values.postgresdb.storage.pv.hostPath }} +--- +{{- end }} +apiVersion: v1 +kind: PersistentVolumeClaim metadata: - name: {{ .Values.postgresdb.pvc.name }} + name: {{ .Values.postgresdb.storage.pvc.name }} labels: release: {{ .Release.Name }} - {{- toYaml .Values.postgresdb.pvc.labels | nindent 4 }} - + {{- toYaml .Values.postgresdb.storage.pvc.labels | nindent 4 }} spec: - #storageClassName: local-path + {{- if ne .Values.postgresdb.storage.type "default" }} + storageClassName: {{ .Values.postgresdb.storage.type }} + {{- end }} accessModes: - ReadWriteOnce - resources: - {{- toYaml .Values.postgresdb.pvc.resources | nindent 4 }} + {{- toYaml .Values.postgresdb.storage.pvc.resources | nindent 4 }} diff --git a/deploy/helm/values-pv.yaml b/deploy/helm/values-pv.yaml new file mode 100644 index 00000000..bf353e14 --- /dev/null +++ b/deploy/helm/values-pv.yaml @@ -0,0 +1,37 @@ +mongodb: + storage: + type: "manual" + pv: + name: mongodb-pv + labels: + app: mongodb + resources: + storage: 2Gi + hostPath: /mnt/test + accessModes: ReadWriteOnce + pvc: + name: mongodb-pv-claim + labels: + app: mongodb + resources: + requests: + storage: 2Gi + +postgresdb: + storage: + type: "manual" + pv: + name: postgres-pv + labels: + app: postgresdb + resources: + storage: 2Gi + hostPath: /mnt/test + pvc: + name: postgres-pv-claim + labels: + app: postgresdb + accessModes: ReadWriteOnce + resources: + requests: + storage: 2Gi \ No newline at end of file diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml index 492b8fc0..7708b1b8 100644 --- a/deploy/helm/values.yaml +++ b/deploy/helm/values.yaml @@ -187,13 +187,23 @@ mongodb: mongoPassword: crapisecretpassword mongoDbName: crapi mongoUri: "admin:crapisecretpassword@mongodb:27017" - pvc: - name: mongodb-pv-claim - labels: - app: mongodb - resources: - requests: - storage: 2Gi + storage: + # type: "manual" + # pv: + # name: mongodb-pv + # labels: + # app: mongodb + # resources: + # storage: 2Gi + # hostPath: /mnt/test + type: "default" + pvc: + name: mongodb-pv-claim + labels: + app: mongodb + resources: + requests: + storage: 2Gi serviceSelectorLabels: app: mongodb podLabels: @@ -221,13 +231,23 @@ postgresdb: postgresUser: admin postgresPassword: crapisecretpassword postgresDbName: crapi - pvc: - name: postgres-pv-claim - labels: - app: postgresdb - resources: - requests: - storage: 2Gi + storage: + # type: "manual" + # pv: + # name: postgres-pv + # labels: + # app: postgresdb + # resources: + # storage: 2Gi + # hostPath: /mnt/test + type: "default" + pvc: + name: postgres-pv-claim + labels: + app: postgresdb + resources: + requests: + storage: 2Gi serviceSelectorLabels: app: postgresdb podLabels: diff --git a/docs/setup.md b/docs/setup.md index edee1d2f..0a0f8f78 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -114,13 +114,22 @@ You can change the smtp configuration if required however all emails with domain ``` git clone [REPOSITORY-URL] ``` - 2. Install the helm chart + + Inorder to manually mount the data to a specific location, hostPath should be updated in values-pv.yaml, and used to install the helm charts. + + ``` + cd deploy/helm + + helm install --namespace crapi crapi . --values values-pv.yaml + ``` + Otherwise install the helm chart normally. ``` cd deploy/helm helm install --namespace crapi crapi . --values values.yaml ``` + 3. If using minikube, create a tunnel to initialize the LoadBalancers ``` minikube tunnel --alsologtostderr diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index bb1ac8f2..135e577e 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -110,3 +110,16 @@ systemctl cat docker.service It will tell you where the docker service file is located. Then edit `/lib/systemd/system/docker.service` with your favorite text editor: append `NetworkManager-wait-online.service` to line 4 (that line should start with the word `After=`) Then run `systemctl daemon-reload` to update your changes to the service file. + +--- + +**5. Problem:** Issues while using hostPath to manually mount the data: + +ERROR: 0/1 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling + +To fix this issue, delete the existing persistent volumes, and start clean. +```Shell +❯ kubectl get pv + +❯ kubectl delete pv {pv_names} +``` \ No newline at end of file