From 5449554f77ee79147f5180cdd7f1ddda097ab2a1 Mon Sep 17 00:00:00 2001 From: muhuchah Date: Fri, 23 Aug 2024 13:33:50 +0330 Subject: [PATCH 1/2] chore(helm): add helm chart --- Chart.yaml | 24 +++++++++++++ templates/configmap.yml | 13 +++++++ templates/deployment-backend.yml | 53 +++++++++++++++++++++++++++ templates/deployment-frontend.yml | 27 ++++++++++++++ templates/deployment-postgres.yml | 60 +++++++++++++++++++++++++++++++ templates/pvc.yml | 10 ++++++ templates/service-backend.yml | 11 ++++++ templates/service-frontend.yml | 11 ++++++ templates/service-postgres.yml | 11 ++++++ values.yaml | 58 ++++++++++++++++++++++++++++++ 10 files changed, 278 insertions(+) create mode 100644 Chart.yaml create mode 100644 templates/configmap.yml create mode 100644 templates/deployment-backend.yml create mode 100644 templates/deployment-frontend.yml create mode 100644 templates/deployment-postgres.yml create mode 100644 templates/pvc.yml create mode 100644 templates/service-backend.yml create mode 100644 templates/service-frontend.yml create mode 100644 templates/service-postgres.yml create mode 100644 values.yaml diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..5fe08ec --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: negar +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/templates/configmap.yml b/templates/configmap.yml new file mode 100644 index 0000000..b531325 --- /dev/null +++ b/templates/configmap.yml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: db-configs + labels: + app: postgres +data: + POSTGRES_DB: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + HOST: "postgres" + PORT: {{ .Values.postgres.port }} + POSTGRES_CONNECTION_STRING: "Host=postgres;Database=postgres;Username=postgres;Password=postgres;" diff --git a/templates/deployment-backend.yml b/templates/deployment-backend.yml new file mode 100644 index 0000000..a36fe92 --- /dev/null +++ b/templates/deployment-backend.yml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend +spec: + replicas: {{ .Values.backend.replicaCount }} + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + initContainers: + - name: migrate + image: {{ .Values.backend.repository }}:{{ .Values.backend.tag }} + imagePullPolicy: {{ .Values.backend.pullPolicy }} + env: + - name: CONNECTION_STRING + valueFrom: + configMapKeyRef: + name: db-configs + key: POSTGRES_CONNECTION_STRING + command: ["dotnet", "./RelationAnalysis.Migrations.dll"] + ports: + - containerPort: {{ .Values.backend.port }} + resources: + requests: + memory: {{ .Values.backend.resources.requests.memory }} + cpu: {{ .Values.backend.resources.requests.cpu }} + limits: + memory: {{ .Values.backend.resources.limits.memory }} + cpu: {{ .Values.backend.resources.limits.cpu }} + containers: + - name: backend + image: {{ .Values.backend.repository }}:{{ .Values.backend.tag }} + imagePullPolicy: {{ .Values.backend.pullPolicy }} + env: + - name: CONNECTION_STRING + valueFrom: + configMapKeyRef: + name: db-configs + key: POSTGRES_CONNECTION_STRING + ports: + - containerPort: {{ .Values.backend.port }} + resources: + requests: + memory: {{ .Values.backend.resources.requests.memory }} + cpu: {{ .Values.backend.resources.requests.cpu }} + limits: + memory: {{ .Values.backend.resources.limits.memory }} + cpu: {{ .Values.backend.resources.limits.cpu }} diff --git a/templates/deployment-frontend.yml b/templates/deployment-frontend.yml new file mode 100644 index 0000000..042749b --- /dev/null +++ b/templates/deployment-frontend.yml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: {{ .Values.frontend.replicaCount }} + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: {{ .Values.frontend.repository }}:{{ .Values.frontend.tag }} + imagePullPolicy: {{ .Values.frontend.pullPolicy }} + ports: + - containerPort: {{ .Values.frontend.port }} + resources: + requests: + memory: {{ .Values.frontend.resources.requests.memory }} + cpu: {{ .Values.frontend.resources.requests.cpu }} + limits: + memory: {{ .Values.frontend.resources.limits.memory }}" + cpu: {{ .Values.frontend.resources.limits.cpu }} diff --git a/templates/deployment-postgres.yml b/templates/deployment-postgres.yml new file mode 100644 index 0000000..105e37d --- /dev/null +++ b/templates/deployment-postgres.yml @@ -0,0 +1,60 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: {{ .Values.postgres.replicaCount }} + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: {{ .Values.postgres.repository }}:{{ .Values.postgres.tag }} + imagePullPolicy: {{ .Values.postgres.pullPolicy }} + ports: + - containerPort: {{ .Values.postgres.port }} + env: + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: db-configs + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + configMapKeyRef: + name: db-configs + key: POSTGRES_PASSWORD + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: db-configs + key: POSTGRES_DB + - name: HOST + valueFrom: + configMapKeyRef: + name: db-configs + key: HOST + - name: PORT + valueFrom: + configMapKeyRef: + name: db-configs + key: PORT + volumeMounts: + - mountPath: /var/lib/postgres/data + name: db-data + resources: + requests: + memory: {{ .Values.postgres.resources.requests.memory }} + cpu: {{ .Values.postgres.resources.requests.cpu }} + limits: + memory: {{ .Values.postgres.resources.limits.memory }} + cpu: {{ .Values.postgres.resources.limits.cpu }} + volumes: + - name: db-data + persistentVolumeClaim: + claimName: db-persistent-pvc diff --git a/templates/pvc.yml b/templates/pvc.yml new file mode 100644 index 0000000..cb624d1 --- /dev/null +++ b/templates/pvc.yml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: db-persistent-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.postgres.pvc.storage }} diff --git a/templates/service-backend.yml b/templates/service-backend.yml new file mode 100644 index 0000000..9d17ac9 --- /dev/null +++ b/templates/service-backend.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: back-service +spec: + type: {{ .Values.backend.service.type }} + selector: + app: backend + ports: + - port: {{ .Values.backend.port }} + targetPort: {{ .Values.backend.service.port }} diff --git a/templates/service-frontend.yml b/templates/service-frontend.yml new file mode 100644 index 0000000..2dc9148 --- /dev/null +++ b/templates/service-frontend.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: front-service +spec: + type: {{ .Values.frontend.service.type }} + selector: + app: frontend + ports: + - port: {{ .Values.frontend.service.port }} + targetPort: {{ .Values.frontend.port }} diff --git a/templates/service-postgres.yml b/templates/service-postgres.yml new file mode 100644 index 0000000..03dd891 --- /dev/null +++ b/templates/service-postgres.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + type: {{ .Values.postgres.service.type }} + ports: + - port: {{ .Values.postgres.port }} + targetPort: {{ .Values.postgres.service.port }} + selector: + app: postgres diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..94a7c63 --- /dev/null +++ b/values.yaml @@ -0,0 +1,58 @@ +backend: + repository: negar-backend + pullPolicy: IfNotPresent + tag: "latest" + replicaCount: 1 + port: 80 + + service: + type: ClusterIP + port: 80 + + resources: + requests: + memory: "256Mi" + cpu: "500m" + limits: + memory: "512Mi" + cpu: "1" + +postgres: + repository: postgres + tag: "16.3" + pullPolicy: IfNotPresent + replicaCount: 1 + port: 5432 + + service: + type: ClusterIP + port: 80 + + resources: + requests: + memory: "500Mi" + cpu: "500m" + limits: + memory: "1Gi" + cpu: "1" + pvc: + storage: 1Gi + +frontend: + repository: negar-frontend + pullPolicy: IfNotPresent + tag: "latest" + replicaCount: 1 + port: 80 + + service: + type: ClusterIP + port: 80 + + resources: + requests: + memory: "256Mi" + cpu: "500m" + limits: + memory: "512Mi" + cpu: "1" From 2e148faf0e68d92c7aab2ba3146082bf983277e2 Mon Sep 17 00:00:00 2001 From: muhuchah Date: Mon, 26 Aug 2024 11:53:26 +0330 Subject: [PATCH 2/2] update values --- templates/configmap.yml | 2 +- templates/deployment-backend.yml | 2 ++ templates/deployment-frontend.yml | 4 ++- templates/ingress.yml | 27 ++++++++++++++++++ templates/pvc.yml | 20 +++++++------- values.yaml | 46 +++++++++++++++++++------------ 6 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 templates/ingress.yml diff --git a/templates/configmap.yml b/templates/configmap.yml index b531325..9df86d1 100644 --- a/templates/configmap.yml +++ b/templates/configmap.yml @@ -9,5 +9,5 @@ data: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" HOST: "postgres" - PORT: {{ .Values.postgres.port }} + PORT: "{{ .Values.postgres.port }}" POSTGRES_CONNECTION_STRING: "Host=postgres;Database=postgres;Username=postgres;Password=postgres;" diff --git a/templates/deployment-backend.yml b/templates/deployment-backend.yml index a36fe92..a84a2a5 100644 --- a/templates/deployment-backend.yml +++ b/templates/deployment-backend.yml @@ -12,6 +12,8 @@ spec: labels: app: backend spec: + imagePullSecrets: + - name: {{ .Values.abrimentImagePullSecret.name }} initContainers: - name: migrate image: {{ .Values.backend.repository }}:{{ .Values.backend.tag }} diff --git a/templates/deployment-frontend.yml b/templates/deployment-frontend.yml index 042749b..b5a095a 100644 --- a/templates/deployment-frontend.yml +++ b/templates/deployment-frontend.yml @@ -12,6 +12,8 @@ spec: labels: app: frontend spec: + imagePullSecrets: + - name: {{ .Values.abrimentImagePullSecret.name }} containers: - name: frontend image: {{ .Values.frontend.repository }}:{{ .Values.frontend.tag }} @@ -23,5 +25,5 @@ spec: memory: {{ .Values.frontend.resources.requests.memory }} cpu: {{ .Values.frontend.resources.requests.cpu }} limits: - memory: {{ .Values.frontend.resources.limits.memory }}" + memory: {{ .Values.frontend.resources.limits.memory }} cpu: {{ .Values.frontend.resources.limits.cpu }} diff --git a/templates/ingress.yml b/templates/ingress.yml new file mode 100644 index 0000000..d50bd4a --- /dev/null +++ b/templates/ingress.yml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: my-ingress + namespace: 0b12e0d24d4541c097bbaab164438125-negar + labels: + app: nginxn +spec: + ingressClassName: my-ingress + rules: + - host: noice.abriment.com + http: + paths: + - path: /api + pathType: Prefix + backend: + service: + name: back-service + port: + number: {{ .Values.backend.service.port }} + - path: / + pathType: Prefix + backend: + service: + name: front-service + port: + number: {{ .Values.frontend.service.port }} diff --git a/templates/pvc.yml b/templates/pvc.yml index cb624d1..8b69ae5 100644 --- a/templates/pvc.yml +++ b/templates/pvc.yml @@ -1,10 +1,10 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: db-persistent-pvc -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.postgres.pvc.storage }} +#apiVersion: v1 +#kind: PersistentVolumeClaim +#metadata: +# name: db-persistent-pvc +#spec: +# accessModes: +# - ReadWriteOnce +# resources: +# requests: +# storage: {{ .Values.postgres.pvc.storage }} diff --git a/values.yaml b/values.yaml index 94a7c63..1f18644 100644 --- a/values.yaml +++ b/values.yaml @@ -1,7 +1,10 @@ backend: - repository: negar-backend + #repository: registry.abriment.com/mhch/negar-backend + repository: docker.arvancloud.ir/mhchah/imagebuilder + #repository: negar-backend pullPolicy: IfNotPresent - tag: "latest" + #pullPolicy: Always + tag: v0.0.3 replicaCount: 1 port: 80 @@ -11,11 +14,11 @@ backend: resources: requests: - memory: "256Mi" - cpu: "500m" + memory: "3000Mi" + cpu: "2000m" limits: - memory: "512Mi" - cpu: "1" + memory: "3000Mi" + cpu: "2000m" postgres: repository: postgres @@ -26,22 +29,25 @@ postgres: service: type: ClusterIP - port: 80 + port: 5432 resources: requests: - memory: "500Mi" - cpu: "500m" + memory: "3000Mi" + cpu: "2000m" limits: - memory: "1Gi" - cpu: "1" + memory: "3000Mi" + cpu: "2000m" pvc: - storage: 1Gi + storage: "3Gi" frontend: - repository: negar-frontend + # repository: docker.arvancloud.ir/mhchah/negar-frontend + #repository: negar-frontend + repository: docker.arvancloud.ir/mhchah/imagebuilder pullPolicy: IfNotPresent - tag: "latest" + # tag: v0.11.3 + tag: v0.0.8 replicaCount: 1 port: 80 @@ -51,8 +57,12 @@ frontend: resources: requests: - memory: "256Mi" - cpu: "500m" + memory: "3000Mi" + cpu: "2000m" limits: - memory: "512Mi" - cpu: "1" + memory: "3000Mi" + cpu: "2000m" + +abrimentImagePullSecret: + name: negar-abrsecret +