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

Add ollama #87

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/ollama/.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/
14 changes: 14 additions & 0 deletions charts/ollama/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: ollama
description: Get up and running with large language models locally.
type: application
version: 0.6.1
appVersion: "0.1.16"
kubeVersion: "^1.16.0-0"
home: https://ollama.ai/
icon: https://ollama.ai/public/ollama.png
keywords:
- ai
- llm
- llama
- mistral
32 changes: 32 additions & 0 deletions charts/ollama/README-IITS.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Usage inside infrastructure-charts

```yaml
ollama:
namespace: ollama
repoURL: "https://charts.my-domain.com"
targetRevision: "0.6.1"
valueFile: "value-files/ollama/values.yaml"
```


value-files/ollama/values.yaml

```yaml
ollama:
ollama:
gpu:
enabled: "true"
ingress:
host: "ollama.my-domain.com"
annotations:
# Adds the oidc proxy upfront
traefik.ingress.kubernetes.io/router.middlewares: "ollama-oidc-forward-auth-ollama@kubernetescrd"
webui:
env:
OLLAMA_API_BASE_URL: "https://ollama.my-domain.com/api"
ingress:
annotations:
# Adds the oidc proxy upfront
traefik.ingress.kubernetes.io/router.middlewares: "ollama-oidc-forward-auth-ollama@kubernetescrd"
host: "ollama.my-domain.com"
```
120 changes: 120 additions & 0 deletions charts/ollama/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ollama.name" -}}
{{- default .Release.Name .Values.ollama.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 "ollama.fullname" -}}
{{- if .Values.ollama.fullnameOverride }}
{{- .Values.ollama.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Release.Name .Values.ollama.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 "ollama.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "ollama.labels" -}}
helm.sh/chart: {{ include "ollama.chart" . }}
{{ include "ollama.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ollama.selectorLabels" -}}
app: {{ include "ollama.name" . }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "ollama.serviceAccountName" -}}
{{- if .Values.ollama.serviceAccount.create }}
{{- default (include "ollama.fullname" .) .Values.ollama.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.ollama.serviceAccount.name }}
{{- end }}
{{- 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 "webui.fullname" -}}
{{- if .Values.webui.fullnameOverride }}
{{- .Values.webui.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Release.Name .Values.webui.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Expand the name of the chart.
*/}}
{{- define "webui.name" -}}
{{- default .Release.Name .Values.webui.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "webui.selectorLabels" -}}
app: {{ include "webui.name" . }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "webui.labels" -}}
helm.sh/chart: {{ include "ollama.chart" . }}
{{ include "webui.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}


{{/*
Create the name of the service account to use
*/}}
{{- define "webui.serviceAccountName" -}}
{{- if .Values.webui.serviceAccount.create }}
{{- default (include "webui.fullname" .) .Values.webui.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.webui.serviceAccount.name }}
{{- end }}
{{- end }}
130 changes: 130 additions & 0 deletions charts/ollama/templates/ollama/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ollama.fullname" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
spec:
strategy:
type: Recreate
{{- if not .Values.ollama.autoscaling.enabled }}
replicas: {{ .Values.ollama.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "ollama.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.ollama.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ollama.labels" . | nindent 8 }}
{{- with .Values.ollama.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.ollama.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "ollama.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.ollama.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.ollama.securityContext | nindent 12 }}
image: "{{ .Values.ollama.image.repository }}:{{ .Values.ollama.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.ollama.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.ollama.service.port }}
protocol: TCP
env:
{{- range $key, $value := .Values.ollama.env }}
- name: {{ printf "%s" $key | replace "." "_" | upper | quote }}
value: {{ tpl $value $ | quote }}
{{- end }}
{{- if or .Values.ollama.ollama.gpu.enabled .Values.ollama.ollama.gpu.enable }}
- name: PATH
value: /usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: LD_LIBRARY_PATH
value: /usr/local/nvidia/lib:/usr/local/nvidia/lib64
- name: NVIDIA_DRIVER_CAPABILITIES
value: compute,utility
{{- end}}
{{- if .Values.ollama.envFromSecret}}
envFrom:
- secretRef:
name: {{.Values.ollama.envFromSecret}}
{{- end }}
{{- if .Values.ollama.resources }}
resources:
{{- $limits := default dict .Values.ollama.resources.limits }}
{{- if or .Values.ollama.ollama.gpu.enabled .Values.ollama.ollama.gpu.enable }}
{{- $gpuLimit := dict "nvidia.com/gpu" (.Values.ollama.ollama.gpu.number | default 1) }}
{{- $limits = merge $limits $gpuLimit }}
{{- end }}
{{- $ressources := merge .Values.ollama.resources (dict "limits" $limits) }}
{{- toYaml $ressources | nindent 12 }}
{{- end}}
volumeMounts:
- name: ollama-data
mountPath: /root/.ollama
{{- with .Values.ollama.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.ollama.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.ollama.livenessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.ollama.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.ollama.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.ollama.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.ollama.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.ollama.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.ollama.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.ollama.readinessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.ollama.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.ollama.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.ollama.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.ollama.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.ollama.readinessProbe.failureThreshold }}
{{- end }}
volumes:
- name: ollama-data
{{- if .Values.ollama.persistentVolume.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.ollama.persistentVolume.existingClaim | default (printf "%s" (include "ollama.fullname" .)) }}
{{- else }}
emptyDir: { }
{{- end }}
{{- with .Values.ollama.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.ollama.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.ollama.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.ollama.ollama.gpu.enabled .Values.ollama.tolerations }}
tolerations:
{{- if or .Values.ollama.ollama.gpu.enabled .Values.ollama.ollama.gpu.enable }}
- key: nvidia.com/gpu
operator: Exists
effect: NoSchedule
{{- end }}
{{- with .Values.ollama.tolerations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/ollama/templates/ollama/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.ollama.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ollama.fullname" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ollama.fullname" . }}
minReplicas: {{ .Values.ollama.autoscaling.minReplicas }}
maxReplicas: {{ .Values.ollama.autoscaling.maxReplicas }}
metrics:
{{- if .Values.ollama.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.ollama.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.ollama.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.ollama.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading