Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: helm chart #183

Merged
merged 14 commits into from
Jun 25, 2024
23 changes: 23 additions & 0 deletions helm/cohere-toolkit/.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/
6 changes: 6 additions & 0 deletions helm/cohere-toolkit/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 15.5.4
digest: sha256:141aac773e977b07030baafa6e55e7c677e23fc913a63b16144d513b23ed67b5
generated: "2024-06-07T12:06:57.91646+01:00"
30 changes: 30 additions & 0 deletions helm/cohere-toolkit/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v2
name: cohere-toolkit
description: A Helm chart for Kubernetes

# 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: "v1.0.5"

dependencies:
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 15.5.4
condition: postgresql.enabled
39 changes: 39 additions & 0 deletions helm/cohere-toolkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
> [!WARNING]
> This helm chart is still experimental and is under active development.
>
> It is not recommended for production use.

## Running on Minikube

1. Create a cluster
```shell
minikube start
```

2. Add your Cohere API key to the [`values/local.yaml`](values/local.yaml) file.
```yaml
cohere:
api_key: "<YOUR_API_KEY>"
```

3. Install the chart
```shell
helm install cohere-toolkit ./helm/cohere-toolkit \
--create-namespace \
-n cohere-toolkit \
-f ./helm/cohere-toolkit/values/local.yaml \
--wait --timeout 30s
```

4. In separate shells, port-forward both backend and frontend services
```shell
kubectl port-forward svc/toolkit-backend 8000:80 -n cohere-toolkit
```
```shell
kubectl port-forward svc/toolkit-frontend 4000:80 -n cohere-toolkit
```

5. Open the frontend in your browser
```shell
open http://localhost:4000
```
18 changes: 18 additions & 0 deletions helm/cohere-toolkit/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cohere-toolkit.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "cohere-toolkit.labels" -}}
helm.sh/chart: {{ include "cohere-toolkit.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
146 changes: 146 additions & 0 deletions helm/cohere-toolkit/templates/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{{- $values := .Values.backend}}

apiVersion: v1
kind: ServiceAccount
metadata:
name: toolkit-backend
namespace: {{ .Release.Namespace }}
labels:
{{- include "cohere-toolkit.labels" . | nindent 4 }}
{{- with $values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $values.serviceAccount.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: toolkit-backend
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: toolkit-backend
{{- include "cohere-toolkit.labels" . | nindent 4 }}
spec:
replicas: {{ $values.replicaCounts }}
selector:
matchLabels:
app.kubernetes.io/name: toolkit-backend
template:
metadata:
name: toolkit-backend
labels:
app.kubernetes.io/name: toolkit-backend
{{- include "cohere-toolkit.labels" . | nindent 8 }}
{{- with $values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: toolkit-backend
securityContext:
{{- toYaml $values.podSecurityContext | nindent 8 }}
containers:
- name: toolkit-backend
image: {{ $values.image.repository }}:{{ $values.image.tag | default .Chart.AppVersion }}
imagePullPolicy: {{ $values.image.pullPolicy }}
securityContext:
{{- toYaml $values.securityContext | nindent 12 }}
resources:
{{- toYaml $values.resources | nindent 12 }}
ports:
- containerPort: 8000
protocol: TCP
name: http
envFrom:
- configMapRef:
name: toolkit-backend
optional: false
- secretRef:
name: toolkit-secrets
optional: false
# TODO: Add livenessProbe and readinessProbe
restartPolicy: Always
{{- with $values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

---

apiVersion: v1
kind: Service
metadata:
name: toolkit-backend
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: toolkit-backend
{{- include "cohere-toolkit.labels" . | nindent 4 }}
spec:
selector:
app.kubernetes.io/name: toolkit-backend
ports:
- protocol: TCP
port: {{ $values.service.port }}
targetPort: http
type: {{ $values.service.type }}

---

{{- if $values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: toolkit-backend
namespace: {{ .Release.Namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: toolkit-backend
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}}

---

apiVersion: v1
kind: ConfigMap
metadata:
name: toolkit-backend
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: toolkit-backend
{{- include "cohere-toolkit.labels" . | nindent 4 }}
data:
{{- toYaml $values.config | nindent 2 }}
Loading
Loading