From ecf8322526e5fb47f6b9f9df80a5dd4abcee830d Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Mon, 14 Oct 2024 00:44:36 +0300 Subject: [PATCH] Add n8n chart --- .gitignore | 1 + .idea/GOHCache.xml | 6 - .idea/codeStyles/Project.xml | 203 ++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 2 +- .idea/inspectionProfiles/Project_Default.xml | 7 + charts/n8n/Chart.yaml | 6 + charts/n8n/README.md | 44 ++++ charts/n8n/templates/_helpers.tpl | 42 ++++ charts/n8n/templates/configmap-n8n.yaml | 8 + charts/n8n/templates/configmap-postgres.yaml | 10 + charts/n8n/templates/deployment-n8n.yaml | 52 +++++ charts/n8n/templates/ingress-n8n.yaml | 31 +++ charts/n8n/templates/secret-postgres.yaml | 11 + charts/n8n/templates/service-n8n.yaml | 16 ++ charts/n8n/templates/service-postgres.yaml | 16 ++ .../n8n/templates/statefulset-postgres.yaml | 64 ++++++ charts/n8n/values.yaml | 36 ++++ 17 files changed, 548 insertions(+), 7 deletions(-) delete mode 100644 .idea/GOHCache.xml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 charts/n8n/Chart.yaml create mode 100644 charts/n8n/README.md create mode 100644 charts/n8n/templates/_helpers.tpl create mode 100644 charts/n8n/templates/configmap-n8n.yaml create mode 100644 charts/n8n/templates/configmap-postgres.yaml create mode 100644 charts/n8n/templates/deployment-n8n.yaml create mode 100644 charts/n8n/templates/ingress-n8n.yaml create mode 100644 charts/n8n/templates/secret-postgres.yaml create mode 100644 charts/n8n/templates/service-n8n.yaml create mode 100644 charts/n8n/templates/service-postgres.yaml create mode 100644 charts/n8n/templates/statefulset-postgres.yaml create mode 100644 charts/n8n/values.yaml diff --git a/.gitignore b/.gitignore index e43b0f9..0e66ee7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/.idea/GOHCache.xml .DS_Store diff --git a/.idea/GOHCache.xml b/.idea/GOHCache.xml deleted file mode 100644 index cb55798..0000000 --- a/.idea/GOHCache.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..c544fb7 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,203 @@ + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index a55e7a1..79ee123 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,5 @@ - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e6d8387 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/charts/n8n/Chart.yaml b/charts/n8n/Chart.yaml new file mode 100644 index 0000000..9649d9f --- /dev/null +++ b/charts/n8n/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +appVersion: "1.62.5" +name: n8n +description: An extendable workflow automation tool. +type: application +version: 0.1.0 diff --git a/charts/n8n/README.md b/charts/n8n/README.md new file mode 100644 index 0000000..0505527 --- /dev/null +++ b/charts/n8n/README.md @@ -0,0 +1,44 @@ +# n8n + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.62.5](https://img.shields.io/badge/AppVersion-1.62.5-informational?style=flat-square) + +An extendable workflow automation tool. + +## Install + +```shell +$ helm upgrade n8n n8n \ + --create-namespace \ + --install \ + --namespace n8n \ + --repo https://th0th.github.io/helm-charts \ + --values values.yaml \ + --version 0.1.0 +``` + +## Uninstall + +```shell +$ helm uninstall --namespace n8n n8n +``` + +## Values + +| Key | Type | Default | Description | +|---------------------------|--------|-----------------------------|--------------------------------------------------------------------------------------------------------------------------| +| encryptionKey | string | `""` | n8n encryption key (see [docs](https://docs.n8n.io/hosting/configuration/environment-variables/deployment/)) | +| env | object | `{}` | environment variables to be passed to n8n (see [docs](https://docs.n8n.io/hosting/configuration/environment-variables/)) | +| image.pullPolicy | string | `"IfNotPresent"` | n8n image pull policy | +| image.repository | string | `"docker.n8n.io/n8nio/n8n"` | n8n image repository | +| image.tag | string | `"1.62.5"` | n8n image tag | +| ingress.annotations | object | `{}` | the ingress annotations | +| ingress.enabled | bool | `false` | enable the ingress | +| ingress.hosts | list | `[]` | the ingress host | +| postgres.database | string | `"n8n"` | the postgres database name | +| postgres.enabled | bool | `true` | enable the postgres statefulset | +| postgres.image.repository | string | `"postgres"` | the postgres image repository | +| postgres.image.tag | string | `"17-alpine"` | the postgres image tag | +| postgres.password | string | `"n8n"` | the postgres password | +| postgres.resources | object | `{}` | resources configuration for the postgres statefulset | +| postgres.user | string | `"n8n"` | the postgres user | +| replicas | int | `1` | number of n8n deployment replicas | | diff --git a/charts/n8n/templates/_helpers.tpl b/charts/n8n/templates/_helpers.tpl new file mode 100644 index 0000000..b91360c --- /dev/null +++ b/charts/n8n/templates/_helpers.tpl @@ -0,0 +1,42 @@ +{{- define "n8n.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "n8n.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{- define "n8n.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "n8n.labels" -}} +helm.sh/chart: {{ include "n8n.chart" . }} +{{ include "n8n.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "n8n.selectorLabels" -}} +app.kubernetes.io/name: {{ include "n8n.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{- define "n8n.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "n8n.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/n8n/templates/configmap-n8n.yaml b/charts/n8n/templates/configmap-n8n.yaml new file mode 100644 index 0000000..af9fc6c --- /dev/null +++ b/charts/n8n/templates/configmap-n8n.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "n8n.fullname" . }}-n8n + labels: + {{- include "n8n.labels" . | nindent 4 }} +data: + {{ .Values.env | toYaml | nindent 2 }} diff --git a/charts/n8n/templates/configmap-postgres.yaml b/charts/n8n/templates/configmap-postgres.yaml new file mode 100644 index 0000000..4c1cdd2 --- /dev/null +++ b/charts/n8n/templates/configmap-postgres.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "n8n.fullname" . }}-postgres + labels: + {{- include "n8n.labels" . | nindent 4 }} +data: + DATABASE: "{{ .Values.postgres.database}}" + HOST: "{{ include "n8n.fullname" . }}-postgres" + PORT: "5432" diff --git a/charts/n8n/templates/deployment-n8n.yaml b/charts/n8n/templates/deployment-n8n.yaml new file mode 100644 index 0000000..652f2cf --- /dev/null +++ b/charts/n8n/templates/deployment-n8n.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + {{- include "n8n.labels" . | nindent 4 }} + name: {{ include "n8n.fullname" . }}-n8n +spec: + replicas: 1 + selector: + matchLabels: + deployment: n8n + {{- include "n8n.selectorLabels" . | nindent 6 }} + strategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + deployment: n8n + {{- include "n8n.selectorLabels" . | nindent 8 }} + spec: + containers: + - env: + - name: DB_TYPE + value: postgresdb + - name: N8N_ENCRYPTION_KEY + value: {{ required "Please set .Values.encryptionKey" .Values.encryptionKey | quote }} + {{ range $key, $value := .Values.env }} + - name: {{ $key }} + value: {{ $value | quote }} + {{ end }} + envFrom: + - configMapRef: + name: {{ include "n8n.fullname" . }}-postgres + optional: false + prefix: DB_POSTGRESDB_ + - secretRef: + name: {{ include "n8n.fullname" . }}-postgres + optional: false + prefix: DB_POSTGRESDB_ + image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + name: n8n + volumeMounts: + - mountPath: /home/node/.n8n + name: data + volumes: + - emptyDir: { } + name: data + diff --git a/charts/n8n/templates/ingress-n8n.yaml b/charts/n8n/templates/ingress-n8n.yaml new file mode 100644 index 0000000..c0504b3 --- /dev/null +++ b/charts/n8n/templates/ingress-n8n.yaml @@ -0,0 +1,31 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + {{- toYaml .Values.ingress.annotations | nindent 4 }} + labels: + {{- include "n8n.labels" . | nindent 4 }} + name: {{ include "n8n.fullname" . }}-n8n +spec: + rules: + {{ $fullName := include "n8n.fullname" . }} + {{ range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - backend: + service: + name: '{{ $fullName }}-n8n' + port: + number: 5678 + path: / + pathType: Prefix + {{ end }} + tls: + - hosts: + {{- range .Values.ingress.hosts }} + - {{ . }} + {{- end }} + secretName: {{ include "n8n.fullname" . }}-n8n-tls +{{- end }} diff --git a/charts/n8n/templates/secret-postgres.yaml b/charts/n8n/templates/secret-postgres.yaml new file mode 100644 index 0000000..bc5cce4 --- /dev/null +++ b/charts/n8n/templates/secret-postgres.yaml @@ -0,0 +1,11 @@ +{{ if .Values.postgres.enabled }} +apiVersion: v1 +kind: Secret +metadata: + labels: + {{- include "n8n.labels" . | nindent 4 }} + name: {{ include "n8n.fullname" . }}-postgres +data: + PASSWORD: {{ required "A valid .Values.postgres.password is required" .Values.postgres.password | b64enc }} + USER: {{ required "A valid .Values.postgres.user is required" .Values.postgres.user | b64enc }} +{{ end }} diff --git a/charts/n8n/templates/service-n8n.yaml b/charts/n8n/templates/service-n8n.yaml new file mode 100644 index 0000000..6620c96 --- /dev/null +++ b/charts/n8n/templates/service-n8n.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "n8n.fullname" . }}-n8n + labels: + {{- include "n8n.labels" . | nindent 4 }} +spec: + type: ClusterIP + selector: + deployment: n8n + {{- include "n8n.selectorLabels" . | nindent 4 }} + ports: + - name: http + port: 5678 + protocol: TCP + targetPort: 5678 diff --git a/charts/n8n/templates/service-postgres.yaml b/charts/n8n/templates/service-postgres.yaml new file mode 100644 index 0000000..db0b1bd --- /dev/null +++ b/charts/n8n/templates/service-postgres.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "n8n.fullname" . }}-postgres + labels: + {{- include "n8n.labels" . | nindent 4 }} +spec: + type: ClusterIP + selector: + statefulSet: postgres + {{- include "n8n.selectorLabels" . | nindent 4 }} + ports: + - name: postgres + port: 5432 + protocol: TCP + targetPort: 5432 diff --git a/charts/n8n/templates/statefulset-postgres.yaml b/charts/n8n/templates/statefulset-postgres.yaml new file mode 100644 index 0000000..92c7e1c --- /dev/null +++ b/charts/n8n/templates/statefulset-postgres.yaml @@ -0,0 +1,64 @@ +{{ if .Values.postgres.enabled }} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + {{- include "n8n.labels" . | nindent 4 }} + name: {{ include "n8n.fullname" . }}-postgres +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + statefulSet: postgres + {{- include "n8n.selectorLabels" . | nindent 6 }} + serviceName: postgres-hl + template: + metadata: + labels: + statefulSet: postgres + {{- include "n8n.selectorLabels" . | nindent 8 }} + name: postgres + spec: + containers: + - env: + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + key: DATABASE + name: {{ include "n8n.fullname" . }}-postgres + optional: false + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: PASSWORD + name: {{ include "n8n.fullname" . }}-postgres + optional: false + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + key: USER + name: {{ include "n8n.fullname" . }}-postgres + optional: false + image: {{ .Values.postgres.image.repository }}:{{ .Values.postgres.image.tag }} + name: postgres + resources: {{- toYaml .Values.postgres.resources | nindent 10 }} + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: data + subPath: postgres + persistentVolumeClaimRetentionPolicy: + whenDeleted: Retain + whenScaled: Retain + volumeClaimTemplates: + - kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: data + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + volumeMode: Filesystem +{{ end}} diff --git a/charts/n8n/values.yaml b/charts/n8n/values.yaml new file mode 100644 index 0000000..77a93fa --- /dev/null +++ b/charts/n8n/values.yaml @@ -0,0 +1,36 @@ +# -- n8n encryption key (see [docs](https://docs.n8n.io/hosting/configuration/environment-variables/deployment/)) +encryptionKey: "" +# -- environment variables to be passed to n8n (see [docs](https://docs.n8n.io/hosting/configuration/environment-variables/)) +env: {} +image: + # -- n8n image pull policy + pullPolicy: IfNotPresent + # -- n8n image repository + repository: docker.n8n.io/n8nio/n8n + # -- n8n image tag + tag: 1.62.5 +ingress: + # -- the ingress annotations + annotations: {} + # -- enable the ingress + enabled: false + # -- the ingress host + hosts: [] +postgres: + # -- the postgres database name + database: n8n + # -- enable the postgres statefulset + enabled: true + image: + # -- the postgres image repository + repository: postgres + # -- the postgres image tag + tag: 17-alpine + # -- the postgres password + password: n8n + # -- resources configuration for the postgres statefulset + resources: {} + # -- the postgres user + user: n8n +# -- number of n8n deployment replicas +replicas: 1