From 12e8fd852c0b3556c448599fedec88aca9191511 Mon Sep 17 00:00:00 2001 From: Arnaud Ritti <77437157+arnaud-ritti@users.noreply.github.com> Date: Mon, 25 Mar 2024 02:37:27 +0100 Subject: [PATCH] feat: add Helm chart (#1186) --- deployment/helm/.gitignore | 3 + deployment/helm/.helmignore | 23 ++ deployment/helm/Chart.lock | 6 + deployment/helm/Chart.yaml | 24 ++ deployment/helm/templates/NOTES.txt | 22 + deployment/helm/templates/_helpers.tpl | 62 +++ deployment/helm/templates/api-deployment.yaml | 110 +++++ deployment/helm/templates/api-hpa.yaml | 32 ++ deployment/helm/templates/api-service.yaml | 15 + .../helm/templates/background-deployment.yaml | 100 +++++ deployment/helm/templates/background-hpa.yaml | 32 ++ deployment/helm/templates/configmap.yaml | 11 + deployment/helm/templates/connector-pvc.yaml | 19 + deployment/helm/templates/dynamic-pvc.yaml | 19 + deployment/helm/templates/ingress.yaml | 60 +++ deployment/helm/templates/secret.yaml | 10 + deployment/helm/templates/serviceaccount.yaml | 13 + .../helm/templates/tests/test-connection.yaml | 15 + deployment/helm/templates/vespa-service.yaml | 23 ++ .../helm/templates/vespa-statefulset.yaml | 83 ++++ .../helm/templates/webserver-deployment.yaml | 93 +++++ deployment/helm/templates/webserver-hpa.yaml | 32 ++ .../helm/templates/webserver-service.yaml | 15 + deployment/helm/values.yaml | 377 ++++++++++++++++++ 24 files changed, 1199 insertions(+) create mode 100644 deployment/helm/.gitignore create mode 100644 deployment/helm/.helmignore create mode 100644 deployment/helm/Chart.lock create mode 100644 deployment/helm/Chart.yaml create mode 100644 deployment/helm/templates/NOTES.txt create mode 100644 deployment/helm/templates/_helpers.tpl create mode 100644 deployment/helm/templates/api-deployment.yaml create mode 100644 deployment/helm/templates/api-hpa.yaml create mode 100644 deployment/helm/templates/api-service.yaml create mode 100644 deployment/helm/templates/background-deployment.yaml create mode 100644 deployment/helm/templates/background-hpa.yaml create mode 100755 deployment/helm/templates/configmap.yaml create mode 100644 deployment/helm/templates/connector-pvc.yaml create mode 100644 deployment/helm/templates/dynamic-pvc.yaml create mode 100644 deployment/helm/templates/ingress.yaml create mode 100755 deployment/helm/templates/secret.yaml create mode 100644 deployment/helm/templates/serviceaccount.yaml create mode 100644 deployment/helm/templates/tests/test-connection.yaml create mode 100644 deployment/helm/templates/vespa-service.yaml create mode 100644 deployment/helm/templates/vespa-statefulset.yaml create mode 100644 deployment/helm/templates/webserver-deployment.yaml create mode 100644 deployment/helm/templates/webserver-hpa.yaml create mode 100644 deployment/helm/templates/webserver-service.yaml create mode 100644 deployment/helm/values.yaml diff --git a/deployment/helm/.gitignore b/deployment/helm/.gitignore new file mode 100644 index 000000000..b442275d6 --- /dev/null +++ b/deployment/helm/.gitignore @@ -0,0 +1,3 @@ +### Helm ### +# Chart dependencies +**/charts/*.tgz diff --git a/deployment/helm/.helmignore b/deployment/helm/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/deployment/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deployment/helm/Chart.lock b/deployment/helm/Chart.lock new file mode 100644 index 000000000..7486bf317 --- /dev/null +++ b/deployment/helm/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 14.1.0 +digest: sha256:526d286ca7143959104d8a7f9b196706efdbd89dcc37943a1b54016f224d4b4d +generated: "2024-02-16T12:21:42.36744+01:00" diff --git a/deployment/helm/Chart.yaml b/deployment/helm/Chart.yaml new file mode 100644 index 000000000..a36131be1 --- /dev/null +++ b/deployment/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: danswer-stack +description: A Helm chart for Kubernetes +home: https://www.danswer.ai/ +sources: + - "https://github.com/danswer-ai/danswer" +type: application +version: 0.1.0 +appVersion: "v0.3.42" +annotations: + category: Productivity + licenses: MIT + images: | + - name: webserver + image: docker.io/danswer/danswer-web-server:v0.3.42 + - name: background + image: docker.io/danswer/danswer-backend:v0.3.42 + - name: vespa + image: vespaengine/vespa:8.277.17 +dependencies: + - name: postgresql + version: "14.1.0" + repository: https://charts.bitnami.com/bitnami + condition: postgresql.enabled \ No newline at end of file diff --git a/deployment/helm/templates/NOTES.txt b/deployment/helm/templates/NOTES.txt new file mode 100644 index 000000000..41703407b --- /dev/null +++ b/deployment/helm/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.webserver.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "danswer-stack.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.webserver.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "danswer-stack.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "danswer-stack.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.webserver.service.port }} +{{- else if contains "ClusterIP" .Values.webserver.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "danswer-stack.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deployment/helm/templates/_helpers.tpl b/deployment/helm/templates/_helpers.tpl new file mode 100644 index 000000000..4e6672fd6 --- /dev/null +++ b/deployment/helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "danswer-stack.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "danswer-stack.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 }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "danswer-stack.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "danswer-stack.labels" -}} +helm.sh/chart: {{ include "danswer-stack.chart" . }} +{{ include "danswer-stack.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "danswer-stack.selectorLabels" -}} +app.kubernetes.io/name: {{ include "danswer-stack.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "danswer-stack.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "danswer-stack.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deployment/helm/templates/api-deployment.yaml b/deployment/helm/templates/api-deployment.yaml new file mode 100644 index 000000000..8c40f3408 --- /dev/null +++ b/deployment/helm/templates/api-deployment.yaml @@ -0,0 +1,110 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "danswer-stack.fullname" . }}-api + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + {{- if not .Values.api.autoscaling.enabled }} + replicas: {{ .Values.api.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "danswer-stack.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.api.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "danswer-stack.labels" . | nindent 8 }} + {{- with .Values.api.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "danswer-stack.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.api.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.api.securityContext | nindent 12 }} + image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.api.image.pullPolicy }} + command: + - "/bin/sh" + - "-c" + - | + alembic upgrade head && + echo "Starting Danswer Api Server" && + uvicorn danswer.main:app --host 0.0.0.0 --port 8080 + ports: + - name: api-server-port + containerPort: {{ .Values.api.service.port }} + protocol: TCP + resources: + {{- toYaml .Values.api.resources | nindent 12 }} + envFrom: + - configMapRef: + name: {{ include "danswer-stack.fullname" . }} + env: + - name: INTERNAL_URL + value: {{ (list "http://" (include "danswer-stack.fullname" .) "-api:" .Values.api.service.port | join "") | quote }} + - name: VESPA_HOST + value: {{ (list (include "danswer-stack.fullname" .) "vespa" | join "-") }} + {{- if .Values.postgresql.enabled }} + - name: POSTGRES_HOST + value: {{ (list .Release.Name "postgresql" | join "-") }} + - name: POSTGRES_DB + value: {{ .Values.postgresql.auth.database }} + - name: POSTGRES_USER + value: {{ .Values.postgresql.auth.username }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ (list .Release.Name "postgresql" | join "-") }} + key: password + {{- end }} + volumeMounts: + - name: dynamic-storage + mountPath: /home/storage + - name: connector-storage + mountPath: /home/file_connector_storage + {{- if .Values.api.volumeMounts }} + {{- .Values.api.volumeMounts | toYaml | nindent 12}} + {{- end }} + volumes: + - name: dynamic-storage + {{- if .Values.persistence.dynamic.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.dynamic.existingClaim | default (list (include "danswer-stack.fullname" .) "dynamic" | join "-") }} + {{- else }} + emptyDir: { } + {{- end }} + - name: connector-storage + {{- if .Values.persistence.connector.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.connector.existingClaim | default (list (include "danswer-stack.fullname" .) "connector" | join "-") }} + {{- else }} + emptyDir: { } + {{- end }} + {{- if .Values.api.volumes }} + {{- .Values.api.volumes | toYaml | nindent 8}} + {{- end }} + {{- with .Values.api.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.api.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.api.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployment/helm/templates/api-hpa.yaml b/deployment/helm/templates/api-hpa.yaml new file mode 100644 index 000000000..378c39715 --- /dev/null +++ b/deployment/helm/templates/api-hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.api.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "danswer-stack.fullname" . }}-api + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "danswer-stack.fullname" . }} + minReplicas: {{ .Values.api.autoscaling.minReplicas }} + maxReplicas: {{ .Values.api.autoscaling.maxReplicas }} + metrics: + {{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deployment/helm/templates/api-service.yaml b/deployment/helm/templates/api-service.yaml new file mode 100644 index 000000000..f4e4e0be6 --- /dev/null +++ b/deployment/helm/templates/api-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "danswer-stack.fullname" . }}-api + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + type: {{ .Values.api.service.type }} + ports: + - port: {{ .Values.api.service.port }} + targetPort: api-server-port + protocol: TCP + name: api-server-port + selector: + {{- include "danswer-stack.selectorLabels" . | nindent 4 }} diff --git a/deployment/helm/templates/background-deployment.yaml b/deployment/helm/templates/background-deployment.yaml new file mode 100644 index 000000000..59cfc5246 --- /dev/null +++ b/deployment/helm/templates/background-deployment.yaml @@ -0,0 +1,100 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "danswer-stack.fullname" . }}-background + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + {{- if not .Values.background.autoscaling.enabled }} + replicas: {{ .Values.background.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "danswer-stack.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.background.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "danswer-stack.labels" . | nindent 8 }} + {{- with .Values.background.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "danswer-stack.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.background.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.background.securityContext | nindent 12 }} + image: "{{ .Values.background.image.repository }}:{{ .Values.background.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.background.image.pullPolicy }} + command: ["/usr/bin/supervisord"] + resources: + {{- toYaml .Values.background.resources | nindent 12 }} + envFrom: + - configMapRef: + name: {{ include "danswer-stack.fullname" . }} + env: + - name: INTERNAL_URL + value: {{ (list "http://" (include "danswer-stack.fullname" .) "-api:" .Values.api.service.port | join "") | quote }} + - name: VESPA_HOST + value: {{ (list (include "danswer-stack.fullname" .) "vespa" | join "-") }} + {{- if .Values.postgresql.enabled }} + - name: POSTGRES_HOST + value: {{ (list .Release.Name "postgresql" | join "-") }} + - name: POSTGRES_DB + value: {{ .Values.postgresql.auth.database }} + - name: POSTGRES_USER + value: {{ .Values.postgresql.auth.username }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ (list .Release.Name "postgresql" | join "-") }} + key: password + {{- end }} + volumeMounts: + - name: dynamic-storage + mountPath: /home/storage + - name: connector-storage + mountPath: /home/file_connector_storage + {{- if .Values.background.volumeMounts }} + {{- .Values.background.volumeMounts | toYaml | nindent 12}} + {{- end }} + volumes: + - name: dynamic-storage + {{- if .Values.persistence.dynamic.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.dynamic.existingClaim | default (list (include "danswer-stack.fullname" .) "dynamic" | join "-") }} + {{- else }} + emptyDir: { } + {{- end }} + - name: connector-storage + {{- if .Values.persistence.connector.enabled }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.connector.existingClaim | default (list (include "danswer-stack.fullname" .) "connector" | join "-") }} + {{- else }} + emptyDir: { } + {{- end }} + {{- if .Values.background.volumes }} + {{- .Values.background.volumes | toYaml | nindent 8}} + {{- end }} + {{- with .Values.background.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.background.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.background.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployment/helm/templates/background-hpa.yaml b/deployment/helm/templates/background-hpa.yaml new file mode 100644 index 000000000..009daf10f --- /dev/null +++ b/deployment/helm/templates/background-hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.background.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "danswer-stack.fullname" . }}-background + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "danswer-stack.fullname" . }} + minReplicas: {{ .Values.background.autoscaling.minReplicas }} + maxReplicas: {{ .Values.background.autoscaling.maxReplicas }} + metrics: + {{- if .Values.background.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.background.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.background.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.background.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deployment/helm/templates/configmap.yaml b/deployment/helm/templates/configmap.yaml new file mode 100755 index 000000000..a39397798 --- /dev/null +++ b/deployment/helm/templates/configmap.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "danswer-stack.fullname" . }} + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +data: +{{- range $key, $value := .Values.config }} + {{ $key }}: |- + {{- $value | nindent 4 }} +{{- end }} diff --git a/deployment/helm/templates/connector-pvc.yaml b/deployment/helm/templates/connector-pvc.yaml new file mode 100644 index 000000000..41c41c3cf --- /dev/null +++ b/deployment/helm/templates/connector-pvc.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.persistence.connector.enabled (not .Values.persistence.connector.existingClaim)}} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "danswer-stack.fullname" . }}-connector + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + accessModes: + {{- range .Values.persistence.connector.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.connector.size | quote }} + {{- with .Values.persistence.connector.storageClassName }} + storageClassName: {{ . }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/deployment/helm/templates/dynamic-pvc.yaml b/deployment/helm/templates/dynamic-pvc.yaml new file mode 100644 index 000000000..703b33acb --- /dev/null +++ b/deployment/helm/templates/dynamic-pvc.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.persistence.dynamic.enabled (not .Values.persistence.dynamic.existingClaim)}} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "danswer-stack.fullname" . }}-dynamic + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + accessModes: + {{- range .Values.persistence.dynamic.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.dynamic.size | quote }} + {{- with .Values.persistence.dynamic.storageClassName }} + storageClassName: {{ . }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/deployment/helm/templates/ingress.yaml b/deployment/helm/templates/ingress.yaml new file mode 100644 index 000000000..cfbef35dd --- /dev/null +++ b/deployment/helm/templates/ingress.yaml @@ -0,0 +1,60 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "danswer-stack.fullname" . -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ (list $fullName .service) | join "-" }} + port: + number: {{ .servicePort }} + {{- else }} + serviceName: {{ (list $fullName .service) | join "-" }} + servicePort: {{ .servicePort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployment/helm/templates/secret.yaml b/deployment/helm/templates/secret.yaml new file mode 100755 index 000000000..58bfba87d --- /dev/null +++ b/deployment/helm/templates/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "danswer-stack.fullname" . }} + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +data: +{{- range $key, $value := .Values.secrets }} + {{ $key }}: '{{ $value | b64enc }}' +{{- end }} diff --git a/deployment/helm/templates/serviceaccount.yaml b/deployment/helm/templates/serviceaccount.yaml new file mode 100644 index 000000000..afd351217 --- /dev/null +++ b/deployment/helm/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "danswer-stack.serviceAccountName" . }} + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/deployment/helm/templates/tests/test-connection.yaml b/deployment/helm/templates/tests/test-connection.yaml new file mode 100644 index 000000000..60fbd1054 --- /dev/null +++ b/deployment/helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "danswer-stack.fullname" . }}-test-connection" + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "danswer-stack.fullname" . }}:{{ .Values.webserver.service.port }}'] + restartPolicy: Never diff --git a/deployment/helm/templates/vespa-service.yaml b/deployment/helm/templates/vespa-service.yaml new file mode 100644 index 000000000..01216a289 --- /dev/null +++ b/deployment/helm/templates/vespa-service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "danswer-stack.fullname" . }}-vespa + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - name: vespa-tenant-port + protocol: TCP + port: 19070 + targetPort: 19070 + - name: vespa-tenant-port-2 + protocol: TCP + port: 19071 + targetPort: 19071 + - name: vespa-port + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + {{- include "danswer-stack.selectorLabels" . | nindent 4 }} diff --git a/deployment/helm/templates/vespa-statefulset.yaml b/deployment/helm/templates/vespa-statefulset.yaml new file mode 100644 index 000000000..674b52bc4 --- /dev/null +++ b/deployment/helm/templates/vespa-statefulset.yaml @@ -0,0 +1,83 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "danswer-stack.fullname" . }}-vespa + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.vespa.replicaCount }} + selector: + matchLabels: + {{- include "danswer-stack.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.vespa.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "danswer-stack.labels" . | nindent 8 }} + {{- with .Values.vespa.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "danswer-stack.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.vespa.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.vespa.securityContext | nindent 12 }} + image: "{{ .Values.vespa.image.repository }}:{{ .Values.vespa.image.tag }}" + imagePullPolicy: {{ .Values.vespa.image.pullPolicy }} + ports: + - containerPort: 19070 + - containerPort: 19071 + - containerPort: 8081 + livenessProbe: + httpGet: + path: /state/v1/health + port: 19071 + scheme: HTTP + readinessProbe: + httpGet: + path: /state/v1/health + port: 19071 + scheme: HTTP + resources: + {{- toYaml .Values.vespa.resources | nindent 12 }} + volumeMounts: + - name: vespa-storage + mountPath: /opt/vespa/var/ + {{- with .Values.vespa.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.vespa.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.vespa.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.persistence.vespa.enabled }} + volumeClaimTemplates: + - metadata: + name: vespa-storage + spec: + accessModes: + {{- range .Values.persistence.vespa.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.vespa.size | quote }} + {{- with .Values.persistence.vespa.storageClassName }} + storageClassName: {{ . }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/deployment/helm/templates/webserver-deployment.yaml b/deployment/helm/templates/webserver-deployment.yaml new file mode 100644 index 000000000..c679e6e0a --- /dev/null +++ b/deployment/helm/templates/webserver-deployment.yaml @@ -0,0 +1,93 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "danswer-stack.fullname" . }}-webserver + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + {{- if not .Values.webserver.autoscaling.enabled }} + replicas: {{ .Values.webserver.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "danswer-stack.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.webserver.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "danswer-stack.labels" . | nindent 8 }} + {{- with .Values.webserver.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "danswer-stack.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.webserver.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.webserver.securityContext | nindent 12 }} + image: "{{ .Values.webserver.image.repository }}:{{ .Values.webserver.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.webserver.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.webserver.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.webserver.resources | nindent 12 }} + envFrom: + - configMapRef: + name: {{ include "danswer-stack.fullname" . }} + env: + - name: INTERNAL_URL + value: {{ (list "http://" (include "danswer-stack.fullname" .) "-api:" .Values.api.service.port | join "") | quote }} + - name: VESPA_HOST + value: {{ (list (include "danswer-stack.fullname" .) "vespa" | join "-") }} + {{- if .Values.postgresql.enabled }} + - name: POSTGRES_HOST + value: {{ (list .Release.Name "postgresql" | join "-") }} + - name: POSTGRES_DB + value: {{ .Values.postgresql.auth.database }} + - name: POSTGRES_USER + value: {{ .Values.postgresql.auth.username }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ (list .Release.Name "postgresql" | join "-") }} + key: password + {{- end }} + {{- with .Values.webserver.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.webserver.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.webserver.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.webserver.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.webserver.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deployment/helm/templates/webserver-hpa.yaml b/deployment/helm/templates/webserver-hpa.yaml new file mode 100644 index 000000000..b46820a7f --- /dev/null +++ b/deployment/helm/templates/webserver-hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.webserver.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "danswer-stack.fullname" . }}-webserver + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "danswer-stack.fullname" . }} + minReplicas: {{ .Values.webserver.autoscaling.minReplicas }} + maxReplicas: {{ .Values.webserver.autoscaling.maxReplicas }} + metrics: + {{- if .Values.webserver.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.webserver.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.webserver.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.webserver.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deployment/helm/templates/webserver-service.yaml b/deployment/helm/templates/webserver-service.yaml new file mode 100644 index 000000000..776b65f8f --- /dev/null +++ b/deployment/helm/templates/webserver-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "danswer-stack.fullname" . }}-webserver + labels: + {{- include "danswer-stack.labels" . | nindent 4 }} +spec: + type: {{ .Values.webserver.service.type }} + ports: + - port: {{ .Values.webserver.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "danswer-stack.selectorLabels" . | nindent 4 }} diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml new file mode 100644 index 000000000..8d994b55f --- /dev/null +++ b/deployment/helm/values.yaml @@ -0,0 +1,377 @@ +# Default values for danswer-stack. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + + +webserver: + replicaCount: 1 + image: + repository: danswer/danswer-web-server + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + podAnnotations: {} + podLabels: {} + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + service: + type: ClusterIP + port: 3000 + + resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + tolerations: [] + affinity: {} + +api: + replicaCount: 1 + image: + repository: danswer/danswer-backend + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + podAnnotations: {} + podLabels: + scope: danswer-backend + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + service: + type: ClusterIP + port: 8080 + + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + requests: + cpu: 1500m + memory: 2Gi + # limits: + # cpu: 100m + # memory: 128Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + tolerations: [] + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: scope + operator: In + values: + - danswer-backend + topologyKey: "kubernetes.io/hostname" + +background: + replicaCount: 1 + image: + repository: danswer/danswer-backend + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + podAnnotations: {} + podLabels: + scope: danswer-backend + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + requests: + cpu: 2500m + memory: 5Gi + # limits: + # cpu: 100m + # memory: 128Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + tolerations: [] + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: scope + operator: In + values: + - danswer-backend + topologyKey: "kubernetes.io/hostname" + +vespa: + replicaCount: 1 + image: + repository: vespaengine/vespa + pullPolicy: IfNotPresent + tag: "8.277.17" + podAnnotations: {} + podLabels: {} + + podSecurityContext: {} + # fsGroup: 2000 + + securityContext: + privileged: true + runAsUser: 0 + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + requests: + cpu: 2500m + memory: 5Gi + # limits: + # cpu: 100m + # memory: 128Mi + + nodeSelector: {} + tolerations: [] + affinity: {} + + +#ingress: +# enabled: false +# className: "" +# annotations: {} +# # kubernetes.io/ingress.class: nginx +# # kubernetes.io/tls-acme: "true" +# hosts: +# - host: chart-example.local +# paths: +# - path: / +# pathType: ImplementationSpecific +# tls: [] +# # - secretName: chart-example-tls +# # hosts: +# # - chart-example.local + +persistence: + vespa: + enabled: true + existingClaim: "" + storageClassName: "" + accessModes: + - ReadWriteOnce + size: 1Gi + connector: + enabled: true + existingClaim: "" + storageClassName: "" + accessModes: + - ReadWriteOnce + size: 1Gi + dynamic: + enabled: true + existingClaim: "" + storageClassName: "" + accessModes: + - ReadWriteOnce + size: 1Gi + +postgresql: + enabled: false + auth: + postgresPassword: "" + username: danswer + password: danswer + database: danswer + +config: + # Auth Setting, also check the secrets file + #AUTH_TYPE: "disabled" # Change this for production uses unless Danswer is only accessible behind VPN + #SESSION_EXPIRE_TIME_SECONDS: "86400" # 1 Day Default + #VALID_EMAIL_DOMAINS: "" # Can be something like danswer.ai, as an extra double-check + #SMTP_SERVER: "" # For sending verification emails, if unspecified then defaults to 'smtp.gmail.com' + #SMTP_PORT: "" # For sending verification emails, if unspecified then defaults to '587' + #SMTP_USER: "" # 'your-email@company.com' + #SMTP_PASS: "" # 'your-gmail-password' + #EMAIL_FROM: "" # 'your-email@company.com' SMTP_USER missing used instead + # Gen AI Settings + #GEN_AI_MODEL_PROVIDER: "openai" + #GEN_AI_MODEL_VERSION: "gpt-4" # "gpt-3.5-turbo-0125" # Use GPT-4 if you have it + #FAST_GEN_AI_MODEL_VERSION: "gpt-3.5-turbo-0125" + #GEN_AI_API_KEY: "" + #GEN_AI_API_ENDPOINT: "" + #GEN_AI_API_VERSION: "" + #GEN_AI_LLM_PROVIDER_TYPE: "" + #GEN_AI_MAX_TOKENS: "" + #QA_TIMEOUT: "60" + #MAX_CHUNKS_FED_TO_CHAT: "" + #DISABLE_LLM_FILTER_EXTRACTION: "" + #DISABLE_LLM_CHUNK_FILTER: "" + #DISABLE_LLM_CHOOSE_SEARCH: "" + # Query Options + #DOC_TIME_DECAY: "" + #HYBRID_ALPHA: "" + #EDIT_KEYWORD_QUERY: "" + #MULTILINGUAL_QUERY_EXPANSION: "" + #QA_PROMPT_OVERRIDE: "" + # Don't change the NLP models unless you know what you're doing + #DOCUMENT_ENCODER_MODEL: "" + #NORMALIZE_EMBEDDINGS: "" + #ASYM_QUERY_PREFIX: "" + #ASYM_PASSAGE_PREFIX: "" + #ENABLE_RERANKING_REAL_TIME_FLOW: "" + #ENABLE_RERANKING_ASYNC_FLOW: "" + #MODEL_SERVER_HOST: "" + #MODEL_SERVER_PORT: "" + #INDEXING_MODEL_SERVER_HOST: "" + #MIN_THREADS_ML_MODELS: "" + # Indexing Configs + #NUM_INDEXING_WORKERS: "" + #DASK_JOB_CLIENT_ENABLED: "" + #CONTINUE_ON_CONNECTOR_FAILURE: "" + #EXPERIMENTAL_CHECKPOINTING_ENABLED: "" + #CONFLUENCE_CONNECTOR_LABELS_TO_SKIP: "" + #GONG_CONNECTOR_START_TIME: "" + #NOTION_CONNECTOR_ENABLE_RECURSIVE_PAGE_LOOKUP: "" + # DanswerBot SlackBot Configs + #DANSWER_BOT_SLACK_APP_TOKEN: "" + #DANSWER_BOT_SLACK_BOT_TOKEN: "" + #DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER: "" + #DANSWER_BOT_DISPLAY_ERROR_MSGS: "" + #DANSWER_BOT_RESPOND_EVERY_CHANNEL: "" + #DANSWER_BOT_DISABLE_COT: "" # Currently unused + #NOTIFY_SLACKBOT_NO_ANSWER: "" + # Logging + # Optional Telemetry, please keep it on (nothing sensitive is collected)? <3 + # https://docs.danswer.dev/more/telemetry + #DISABLE_TELEMETRY: "" + #LOG_LEVEL: "" + #LOG_ALL_MODEL_INTERACTIONS: "" + #LOG_VESPA_TIMING_INFORMATION: "" + # Shared or Non-backend Related + #INTERNAL_URL: "http://api-server-service:80" # for web server + WEB_DOMAIN: "http://localhost:3000" # for web server and api server + # Other Services + #POSTGRES_HOST: "relational-db-service" + #VESPA_HOST: "document-index-service" \ No newline at end of file