diff --git a/deploy/helm/.helmignore b/deploy/helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/deploy/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/deploy/helm/Chart.yaml b/deploy/helm/Chart.yaml new file mode 100644 index 0000000..c0df337 --- /dev/null +++ b/deploy/helm/Chart.yaml @@ -0,0 +1,25 @@ +apiVersion: v2 +name: llamagpt +description: A Helm chart for Kubernetes +icon: https://i.imgur.com/LI59cui.png + +# 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.0.1" diff --git a/deploy/helm/templates/_helpers.tpl b/deploy/helm/templates/_helpers.tpl new file mode 100644 index 0000000..36ad009 --- /dev/null +++ b/deploy/helm/templates/_helpers.tpl @@ -0,0 +1,66 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "llamagpt.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 "llamagpt.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 "llamagpt.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "llamagpt.labels" -}} +helm.sh/chart: {{ include "llamagpt.chart" . }} +{{ include "llamagpt.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "llamagpt.selectorLabels" -}} +app.kubernetes.io/name: {{ include "llamagpt.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "llamagpt.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "llamagpt.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "llamagpt.api.openAi.host" -}} +{{- default (printf "%s-api:%v" (include "llamagpt.fullname" .) .Values.api.service.port) .Values.api.openAi.host }} +{{- end }} diff --git a/deploy/helm/templates/configmap.yaml b/deploy/helm/templates/configmap.yaml new file mode 100644 index 0000000..c56e066 --- /dev/null +++ b/deploy/helm/templates/configmap.yaml @@ -0,0 +1,16 @@ +--- + +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ template "llamagpt.fullname" . }}-configmap + labels: + {{- include "llamagpt.labels" . | nindent 4 }} +data: + DEFAULT_MODEL: {{ .Values.api.defaultModel }} + OPENAI_API_HOST: http://{{ template "llamagpt.api.openAi.host" . }} + OPENAI_API_KEY: {{ .Values.api.openAi.key }} + WAIT_HOSTS: {{ template "llamagpt.api.openAi.host" . }} + WAIT_TIMEOUT: {{ quote .Values.api.openAi.waitTimeout }} + +--- diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml new file mode 100644 index 0000000..1cbbfcf --- /dev/null +++ b/deploy/helm/templates/deployment.yaml @@ -0,0 +1,66 @@ +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + service: {{ template "llamagpt.fullname" . }}-api + {{- include "llamagpt.labels" . | nindent 4 }} + name: {{ template "llamagpt.fullname" . }}-api +spec: + replicas: {{ .Values.api.replicas }} + selector: + matchLabels: + service: {{ template "llamagpt.fullname" . }}-api + template: + metadata: + labels: + service: {{ template "llamagpt.fullname" . }}-api + {{- include "llamagpt.labels" . | nindent 4 }} + spec: + containers: + - name: {{ template "llamagpt.fullname" . }}-api + image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag }}" + env: + - name: MODEL + valueFrom: + configMapKeyRef: + name: {{ template "llamagpt.fullname" . }}-configmap + key: DEFAULT_MODEL + resources: + requests: + memory: {{ .Values.api.resources.memory }} + restartPolicy: {{ .Values.api.restartPolicy }} + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + service: {{ template "llamagpt.fullname" . }}-ui + {{- include "llamagpt.labels" . | nindent 4 }} + name: {{ template "llamagpt.fullname" . }}-ui +spec: + replicas: {{ .Values.ui.replicas }} + selector: + matchLabels: + service: {{ template "llamagpt.fullname" . }}-ui + template: + metadata: + labels: + service: {{ template "llamagpt.fullname" . }}-ui + {{- include "llamagpt.labels" . | nindent 4 }} + spec: + containers: + - name: {{ template "llamagpt.fullname" . }}-ui + image: "{{ .Values.ui.image.repository }}:{{ .Values.ui.image.tag }}" + envFrom: + - configMapRef: + name: {{ template "llamagpt.fullname" . }}-configmap + ports: + - containerPort: {{ int .Values.ui.service.internalPort }} + resources: {} + restartPolicy: {{ .Values.ui.restartPolicy }} + +--- diff --git a/deploy/helm/templates/service.yaml b/deploy/helm/templates/service.yaml new file mode 100644 index 0000000..329cf5a --- /dev/null +++ b/deploy/helm/templates/service.yaml @@ -0,0 +1,40 @@ +--- + +apiVersion: v1 +kind: Service +metadata: + labels: + service: {{ template "llamagpt.fullname" . }} + {{- include "llamagpt.labels" . | nindent 4 }} + name: {{ template "llamagpt.fullname" . }}-api +spec: + ports: + - name: api + port: {{ .Values.api.service.port }} + targetPort: {{ .Values.api.service.targetPort }} + selector: + service: {{ template "llamagpt.fullname" . }}-api +status: + loadBalancer: {} + +--- + +apiVersion: v1 +kind: Service +metadata: + labels: + service: {{ template "llamagpt.fullname" . }}-ui + {{- include "llamagpt.labels" . | nindent 4 }} + name: {{ template "llamagpt.fullname" . }}-ui +spec: + ports: + - name: ui + port: {{ .Values.ui.service.port }} + targetPort: {{ .Values.ui.service.targetPort }} + selector: + service: {{ template "llamagpt.fullname" . }}-ui + type: {{ .Values.ui.service.type }} +status: + loadBalancer: {} + +--- diff --git a/deploy/helm/templates/tests/test-connection.yaml b/deploy/helm/templates/tests/test-connection.yaml new file mode 100644 index 0000000..60dc69c --- /dev/null +++ b/deploy/helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "llamagpt.fullname" . }}-test-connection" + labels: + {{- include "llamagpt.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ template "llamagpt.fullname" . }}-ui:{{ .Values.ui.service.port }}'] + restartPolicy: Never diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml new file mode 100644 index 0000000..f3f5a3c --- /dev/null +++ b/deploy/helm/values.yaml @@ -0,0 +1,37 @@ +# Default values for llamagpt. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +ui: + replicaCount: 1 + service: + type: ClusterIP + port: 3000 + targetPort: 3000 + internalPort: 3000 + image: + repository: ghcr.io/getumbrel/llama-gpt-ui + tag: 1.0.1 + pullPolicy: IfNotPresent + affinity: {} + restartPolicy: Always + +api: + defaultModel: /models/llama-2-7b-chat.bin + replicaCount: 1 + service: + type: ClusterIP + port: 8000 + targetPort: 8000 + image: + repository: ghcr.io/getumbrel/llama-gpt-api + tag: 1.0.1 + pullPolicy: IfNotPresent + affinity: {} + restartPolicy: Always + resources: + memory: 5Gi + openAi: + host: + key: sk-XXXXXXXXXXXXXXXXXXXX + waitTimeout: 600