diff --git a/kubernetes/helm-charts/Taskfile.yml b/kubernetes/helm-charts/Taskfile.yml new file mode 100644 index 0000000..33821a8 --- /dev/null +++ b/kubernetes/helm-charts/Taskfile.yml @@ -0,0 +1,16 @@ +--- +version: '3' +tasks: + default: + cmds: + - | + helm upgrade \ + --create-namespace \ + -n bricksllm \ + --install \ + bricksllm \ + ./bricksllm + delete: + cmds: + - helm delete -n bricksllm bricksllm + diff --git a/kubernetes/helm-charts/bricksllm/.gitignore b/kubernetes/helm-charts/bricksllm/.gitignore new file mode 100644 index 0000000..948259a --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/.gitignore @@ -0,0 +1 @@ +charts/*.tgz diff --git a/kubernetes/helm-charts/bricksllm/.helmignore b/kubernetes/helm-charts/bricksllm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/.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/kubernetes/helm-charts/bricksllm/Chart.lock b/kubernetes/helm-charts/bricksllm/Chart.lock new file mode 100644 index 0000000..322694a --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/Chart.lock @@ -0,0 +1,9 @@ +dependencies: +- name: redis + repository: oci://registry-1.docker.io/bitnamicharts + version: 20.2.1 +- name: postgresql + repository: oci://registry-1.docker.io/bitnamicharts + version: 16.1.1 +digest: sha256:d380aeee84575489c7b48727ff37b9e47747e8c7e855655fc815455243421660 +generated: "2024-11-04T22:16:50.627919824Z" diff --git a/kubernetes/helm-charts/bricksllm/Chart.yaml b/kubernetes/helm-charts/bricksllm/Chart.yaml new file mode 100644 index 0000000..7b918a3 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/Chart.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v2 +name: bricksllm +description: A Helm chart for deploying BricksLLM and its dependencies + +type: application + +version: 0.1.0 + +# bricksllm version +appVersion: "1.37.0" + +dependencies: + - condition: redis.enabled + name: redis + repository: oci://registry-1.docker.io/bitnamicharts + version: ~20 + - conditions: postgresql.enabled + name: postgresql + repository: oci://registry-1.docker.io/bitnamicharts + version: ~16 diff --git a/kubernetes/helm-charts/bricksllm/templates/NOTES.txt b/kubernetes/helm-charts/bricksllm/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/kubernetes/helm-charts/bricksllm/templates/_helpers.tpl b/kubernetes/helm-charts/bricksllm/templates/_helpers.tpl new file mode 100644 index 0000000..7a986ec --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "bricksllm.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 "bricksllm.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 "bricksllm.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "bricksllm.labels" -}} +helm.sh/chart: {{ include "bricksllm.chart" . }} +{{ include "bricksllm.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "bricksllm.selectorLabels" -}} +app.kubernetes.io/name: {{ include "bricksllm.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "bricksllm.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "bricksllm.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/kubernetes/helm-charts/bricksllm/templates/deployment.yaml b/kubernetes/helm-charts/bricksllm/templates/deployment.yaml new file mode 100644 index 0000000..f015f69 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/deployment.yaml @@ -0,0 +1,95 @@ +{{ $fullname := include "bricksllm.fullname" . -}} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ $fullname }} + labels: + {{- include "bricksllm.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "bricksllm.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "bricksllm.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "bricksllm.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + env: + - name: POSTGRESQL_HOSTS + value: '{{ $fullname }}-postgresql' + - name: POSTGRESQL_USERNAME + value: postgres + - name: POSTGRESQL_PASSWORD + valueFrom: + secretKeyRef: + name: '{{ $fullname }}-postgresql' + key: postgres-password + - name: REDIS_HOSTS + value: '{{ $fullname }}-redis-master' + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: '{{ $fullname }}-redis' + key: redis-password + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + {{- range $n, $p := .Values.services.ports }} + - name: {{ $n }} + containerPort: {{ $p }} + protocol: TCP + {{- end }} + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinesProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/kubernetes/helm-charts/bricksllm/templates/hpa.yaml b/kubernetes/helm-charts/bricksllm/templates/hpa.yaml new file mode 100644 index 0000000..bd8bff1 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "bricksllm.fullname" . }} + labels: + {{- include "bricksllm.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "bricksllm.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/kubernetes/helm-charts/bricksllm/templates/ingress.yaml b/kubernetes/helm-charts/bricksllm/templates/ingress.yaml new file mode 100644 index 0000000..fcbb9dc --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/ingress.yaml @@ -0,0 +1,50 @@ +{{- $fullname := include "bricksllm.fullname" . }} +{{- $labels := include "bricksllm.labels" . }} +{{- range $name, $v := .Values.ingresses }} +{{- if $v.enabled }} +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullname }}-{{ $name }} + labels: + {{- $labels | nindent 4 }} + {{- with $v.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with $v.className }} + ingressClassName: {{ . }} + {{- end }} + {{- if $v.tls }} + tls: + {{- range $v.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + {{- with .secretName }} + secretName: {{ . }} + {{- end }} + {{- end }} + {{- end }} + rules: + {{- range $v.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: {{ $fullname }} + port: + name: {{ $name | quote }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} diff --git a/kubernetes/helm-charts/bricksllm/templates/service.yaml b/kubernetes/helm-charts/bricksllm/templates/service.yaml new file mode 100644 index 0000000..f8441d1 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/service.yaml @@ -0,0 +1,21 @@ +{{- $fullname := include "bricksllm.fullname" . }} +{{- $labels := include "bricksllm.labels" . }} +{{- $selectorLabels := include "bricksllm.selectorLabels" . }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $fullname }} + labels: + {{- $labels | nindent 4 }} +spec: + type: {{ .Values.services.type }} + ports: +{{- range $n, $p := .Values.services.ports }} + - port: {{ $p }} + targetPort: {{ $p }} + protocol: TCP + name: {{ $n | quote }} +{{- end }} + selector: + {{- $selectorLabels | nindent 4 }} diff --git a/kubernetes/helm-charts/bricksllm/templates/serviceaccount.yaml b/kubernetes/helm-charts/bricksllm/templates/serviceaccount.yaml new file mode 100644 index 0000000..453e1e0 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "bricksllm.serviceAccountName" . }} + labels: + {{- include "bricksllm.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/kubernetes/helm-charts/bricksllm/templates/tests/test-connection.yaml b/kubernetes/helm-charts/bricksllm/templates/tests/test-connection.yaml new file mode 100644 index 0000000..32b4f42 --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/templates/tests/test-connection.yaml @@ -0,0 +1,21 @@ +{{ $fullname := include "bricksllm.fullname" . -}} +--- +apiVersion: v1 +kind: Pod +metadata: + name: "{{ $fullname }}-test-connection" + labels: + {{- include "bricksllm.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: +{{- range $n, $p := .Values.services.ports }} + - name: wget + image: busybox + command: + - wget + args: + - '{{ $fullname }}:{{ $p }}' +{{- end }} + restartPolicy: Never diff --git a/kubernetes/helm-charts/bricksllm/values.yaml b/kubernetes/helm-charts/bricksllm/values.yaml new file mode 100644 index 0000000..72bc6ea --- /dev/null +++ b/kubernetes/helm-charts/bricksllm/values.yaml @@ -0,0 +1,128 @@ +--- +# replica count for the bricksllm Deployment +replicaCount: 1 + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: luyuanxin1995/bricksllm + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# for private registries hosting the imagery +imagePullSecrets: [] + +# This is to override the chart name. +nameOverride: "" +fullnameOverride: "" + +# establish a dedicated service account +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: "" + +# additional pod annotations +podAnnotations: {} + +# additional pod labels +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +services: + type: ClusterIP + ports: + admin: 8001 + proxy: 8002 + +# Configuring Ingresses +ingresses: + admin: + enabled: false + #className: "tailscale" + #annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + #hosts: + # - host: bricksllm-admin.elephant-frog.ts.net + # paths: + # - path: / + # pathType: ImplementationSpecific + #tls: + # - hosts: + # - bricksllm-admin.elephant-frog.ts.net + proxy: + enabled: false + #className: tailscale + #annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + #hosts: + # - host: bricksllm-proxy.elephant-frog.ts.net + # paths: + # - path: / + # pathType: ImplementationSpecific + #tls: + # - hosts: + # - bricksllm-proxy.elephant-frog.ts.net + +#resources: +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi + +livenessProbe: + httpGet: + path: /api/health + port: proxy + +readinessProbe: + httpGet: + path: /api/health + port: proxy + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes for the Deployments +#volumes: +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts for the deployments +#volumeMounts: +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {}