Skip to content

Commit

Permalink
Merge pull request #92 from andrewrothstein/feature/add-k8s-helm-chart
Browse files Browse the repository at this point in the history
A helm chart for BricksLLM fun in Kubernetes
  • Loading branch information
spikelu2016 authored Dec 6, 2024
2 parents 25627cc + 0bbcd74 commit c101ce8
Show file tree
Hide file tree
Showing 14 changed files with 492 additions and 0 deletions.
16 changes: 16 additions & 0 deletions kubernetes/helm-charts/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions kubernetes/helm-charts/bricksllm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts/*.tgz
23 changes: 23 additions & 0 deletions kubernetes/helm-charts/bricksllm/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
9 changes: 9 additions & 0 deletions kubernetes/helm-charts/bricksllm/Chart.lock
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions kubernetes/helm-charts/bricksllm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
Empty file.
62 changes: 62 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
95 changes: 95 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 32 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
50 changes: 50 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions kubernetes/helm-charts/bricksllm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit c101ce8

Please sign in to comment.