first backup of charts

This commit is contained in:
Ivan087
2025-09-23 10:01:17 +08:00
commit cbfc0104a6
170 changed files with 17788 additions and 0 deletions

View File

@ -0,0 +1,25 @@
1. Get the application URL by running these commands:
{{- if .Values.knative.enabled }}
export KSERVICE_URL=$(kubectl get ksvc --namespace {{ .Release.Namespace }} {{ include "ollama.fullname" . }} -o jsonpath={.status.url})
echo "Visit $KSERVICE_URL to use your application"
{{- else if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ollama.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "ollama.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ollama.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "ollama.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}

View File

@ -0,0 +1,80 @@
{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
*/}}
{{- define "ollama.namespace" -}}
{{- if .Values.namespaceOverride -}}
{{- .Values.namespaceOverride -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}
{{/*
Expand the name of the chart.
*/}}
{{- define "ollama.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 "ollama.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 "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.kubernetes.io/name: {{ include "ollama.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "ollama.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ollama.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Models mount path
*/}}
{{- define "ollama.modelsMountPath" -}}
{{- printf "%s/models" (((.Values).ollama).mountPath | default "/root/.ollama") }}
{{- end -}}

View File

@ -0,0 +1,293 @@
---
{{- if not .Values.knative.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.deployment.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- if or .Values.updateStrategy.type .Values.updateStrategy.rollingUpdate }}
strategy: {{ .Values.updateStrategy | toYaml | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "ollama.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ollama.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- if .Values.hostIPC }}
hostIPC: {{ .Values.hostIPC }}
{{- end }}
{{- if .Values.hostPID }}
hostPID: {{ .Values.hostPID }}
{{- end }}
{{- if .Values.hostNetwork }}
hostNetwork: {{ .Values.hostNetwork }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "ollama.serviceAccountName" . }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName | quote }}
{{- end }}
{{- if .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- if .Values.runtimeClassName }}
runtimeClassName: {{ .Values.runtimeClassName | quote }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- tpl (toYaml . ) $ | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default (ternary (printf "%s-rocm" .Chart.AppVersion) (.Chart.AppVersion) (and (.Values.ollama.gpu.enabled) (eq .Values.ollama.gpu.type "amd"))) }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.ollama.port }}
protocol: TCP
env:
- name: OLLAMA_HOST
value: "0.0.0.0:{{ .Values.ollama.port }}"
{{- if and .Values.ollama.gpu.enabled (or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type))}}
- name: PATH
value: /usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
{{- end}}
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
{{- with .Values.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
args:
{{- with .Values.extraArgs }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.resources }}
resources:
{{- $limits := default dict .Values.resources.limits }}
{{- if .Values.ollama.gpu.enabled }}
{{- if .Values.ollama.gpu.draEnabled}}
claims:
- name: gpu
{{- else }}
# If gpu is enabled, it can either be a NVIDIA card or a AMD card
{{- if or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type) }}
# NVIDIA is assumed by default if no value is set and GPU is enabled
# NVIDIA cards can have mig enabled (i.e., the card is sliced into parts
# Therefore, the first case is no migs enabled
{{- if or (not .Values.ollama.gpu.mig) (not .Values.ollama.gpu.mig.enabled ) }}
{{- $gpuLimit := dict (.Values.ollama.gpu.nvidiaResource | default "nvidia.com/gpu") (.Values.ollama.gpu.number | default 1) }}
{{- $limits = merge $limits $gpuLimit }}
# Second case is mig is enabled
{{- else if or (.Values.ollama.gpu.mig.enabled) }}
# Initialize empty dictionary
{{- $migDevices := dict -}}
# Loop over the entries in the mig devices
{{- range $key, $value := .Values.ollama.gpu.mig.devices }}
{{- $migKey := printf "nvidia.com/mig-%s" $key -}}
{{- $migDevices = merge $migDevices (dict $migKey $value) -}}
{{- end }}
{{- $limits = merge $limits $migDevices}}
{{- end }}
{{- end }}
{{- if eq .Values.ollama.gpu.type "amd" }}
{{- $gpuLimit := dict "amd.com/gpu" (.Values.ollama.gpu.number | default 1) }}
{{- $limits = merge $limits $gpuLimit }}
{{- end }}
{{- end }}
{{- end }}
{{- $ressources := deepCopy (dict "limits" $limits) | mergeOverwrite .Values.resources }}
{{- toYaml $ressources | nindent 12 }}
{{- end}}
volumeMounts:
- name: ollama-data
mountPath: {{ .Values.ollama.mountPath | default "/root/.ollama" }}
{{- if .Values.persistentVolume.subPath }}
subPath: {{ .Values.persistentVolume.subPath }}
{{- end }}
{{- range .Values.ollama.models.create }}
{{- if .configMapRef }}
- name: {{ .name }}-config-model-volume
mountPath: /models
{{- end }}
{{- end }}
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.readinessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
{{- end }}
{{- with .Values.lifecycle}}
lifecycle:
{{- toYaml . | nindent 12 }}
{{- else }}
{{- if or .Values.ollama.models.pull .Values.ollama.models.run .Values.ollama.models.create }}
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- |
while ! /bin/ollama ps > /dev/null 2>&1; do
sleep 5
done
{{- $allModels := list -}}
{{- if .Values.ollama.models.pull }}
{{- range .Values.ollama.models.pull }}
{{- if contains ":" . }}
{{- $allModels = append $allModels . }}
{{- else }}
{{- $allModels = append $allModels (printf "%s:latest" .) }}
{{- end }}
/bin/ollama pull {{ternary "--insecure" "" $.Values.ollama.insecure | toString }} {{ . }}
{{- end }}
{{- end }}
{{- if .Values.ollama.models.create }}
{{- range .Values.ollama.models.create }}
{{- $allModels = append $allModels .name }}
{{- if .template }}
cat <<EOF > {{ include "ollama.modelsMountPath" $ }}/{{ .name }}
{{- .template | nindent 20 }}
EOF
/bin/ollama create {{ .name }} -f {{ include "ollama.modelsMountPath" $ }}/{{ .name }}
{{- end }}
{{- if .configMapRef }}
/bin/ollama create {{ .name }} -f /models/{{ .name }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.ollama.models.run }}
{{- range .Values.ollama.models.run }}
{{- if contains ":" . }}
{{- $allModels = append $allModels . }}
{{- else }}
{{- $allModels = append $allModels (printf "%s:latest" .) }}
{{- end }}
/bin/ollama run {{ . }}
{{- end }}
{{- end }}
{{- if .Values.ollama.models.clean }}
/bin/ollama list | awk 'NR>1 {print $1}' | while read model; do
echo "{{ $allModels | join " " }}" | tr ' ' '\n' | grep -Fqx "$model" || /bin/ollama rm "$model"
done
{{- end }}
{{- end }}
{{- end }}
{{- if and .Values.ollama.gpu.enabled .Values.ollama.gpu.draEnabled }}
resourceClaims:
- name: gpu
resourceClaimTemplateName: {{ .Values.ollama.gpu.draExistingClaimTemplate | default (printf "%s" (include "ollama.fullname" .)) }}
{{- end }}
volumes:
- name: ollama-data
{{- if .Values.persistentVolume.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.persistentVolume.existingClaim | default (printf "%s" (include "ollama.fullname" .)) }}
{{- else }}
emptyDir: { }
{{- end }}
{{- range .Values.ollama.models.create }}
{{- if .configMapRef }}
- name: {{ .name }}-config-model-volume
configMap:
name: {{ .configMapRef }}
items:
- key: {{ .configMapKeyRef }}
path: {{ .name }}
{{- end }}
{{- end }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.ollama.gpu.enabled .Values.tolerations }}
tolerations:
{{- if and .Values.ollama.gpu.enabled (and
( or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type))
( or (not .Values.ollama.gpu.mig) (not .Values.ollama.gpu.mig.enabled))
) }}
- key: "{{(.Values.ollama.gpu.nvidiaResource | default "nvidia.com/gpu")}}"
operator: Exists
effect: NoSchedule
{{- else if and .Values.ollama.gpu.enabled (and
( or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type))
(( .Values.ollama.gpu.mig.enabled))
) }}
{{- range $key, $value := .Values.ollama.gpu.mig.devices }}
- key: nvidia.com/mig-{{ $key }}
operator: Exists
effect: NoSchedule
{{- end }}
{{- end }}
{{- with .Values.tolerations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,4 @@
{{ range .Values.extraObjects }}
---
{{ tpl (toYaml .) $ }}
{{ end }}

View File

@ -0,0 +1,34 @@
---
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ollama.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 }}

View File

@ -0,0 +1,63 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "ollama.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className }}
{{- end }}
{{- end }}
---
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,200 @@
---
{{- if .Values.knative.enabled }}
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: {{ include "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.knative.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
template:
spec:
containerConcurrency: {{ .Values.knative.containerConcurrency }}
timeoutSeconds: {{ .Values.knative.timeoutSeconds }}
responseStartTimeoutSeconds: {{ .Values.knative.responseStartTimeoutSeconds }}
idleTimeoutSeconds: {{ .Values.knative.idleTimeoutSeconds }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "ollama.serviceAccountName" . }}
{{- if .Values.runtimeClassName }}
runtimeClassName: {{ .Values.runtimeClassName | quote }}
{{- end }}
{{- if .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- tpl (toYaml . ) $ | nindent 8 }}
{{- end }}
containers:
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default (ternary (printf "%s-rocm" .Chart.AppVersion) (.Chart.AppVersion) (and (.Values.ollama.gpu.enabled) (eq .Values.ollama.gpu.type "amd"))) }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
ports:
- containerPort: {{ .Values.ollama.port }}
env:
- name: OLLAMA_HOST
value: "0.0.0.0:{{ .Values.ollama.port }}"
{{- if and .Values.ollama.gpu.enabled (or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type))}}
- name: PATH
value: /usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
{{- end}}
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
{{- with .Values.extraEnvFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
args:
{{- with .Values.extraArgs }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.resources }}
resources:
{{- $limits := default dict .Values.resources.limits }}
{{- if .Values.ollama.gpu.enabled }}
{{- if or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type) }}
{{- $gpuLimit := dict (.Values.ollama.gpu.nvidiaResource | default "nvidia.com/gpu") (.Values.ollama.gpu.number | default 1) }}
{{- $limits = merge $limits $gpuLimit }}
{{- end }}
{{- if eq .Values.ollama.gpu.type "amd" }}
{{- $gpuLimit := dict "amd.com/gpu" (.Values.ollama.gpu.number | default 1) }}
{{- $limits = merge $limits $gpuLimit }}
{{- end }}
{{- end }}
{{- $ressources := deepCopy (dict "limits" $limits) | mergeOverwrite .Values.resources }}
{{- toYaml $ressources | nindent 12 }}
{{- end}}
volumeMounts:
- name: ollama-data
mountPath: {{ .Values.ollama.mountPath | default "/root/.ollama" }}
{{- if .Values.persistentVolume.subPath }}
subPath: {{ .Values.persistentVolume.subPath }}
{{- end }}
{{- range .Values.ollama.models.create }}
{{- if .configMapRef }}
- name: {{ .name }}-config-model-volume
mountPath: /models
{{- end }}
{{- end }}
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.readinessProbe.path }}
port: http
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
{{- end }}
{{- with .Values.lifecycle}}
lifecycle:
{{- toYaml . | nindent 12 }}
{{- else }}
{{- if or .Values.ollama.models.pull .Values.ollama.models.run .Values.ollama.models.create }}
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- |
while ! /bin/ollama ps > /dev/null 2>&1; do
sleep 5
done
{{- if .Values.ollama.models.pull }}
{{- range .Values.ollama.models.pull }}
/bin/ollama pull {{ternary "--insecure" "" $.Values.ollama.insecure | toString }} {{ . }}
{{- end }}
{{- end }}
{{- if .Values.ollama.models.create }}
{{- range .Values.ollama.models.create }}
{{- if .template }}
cat <<EOF > {{ include "ollama.modelsMountPath" $ }}/{{ .name }}
{{- .template | nindent 20 }}
EOF
/bin/ollama create {{ .name }} -f {{ include "ollama.modelsMountPath" . }}/{{ .name }}
{{- end }}
{{- if .configMapRef }}
/bin/ollama create {{ .name }} -f /models/{{ .name }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.ollama.models.run }}
{{- range .Values.ollama.models.run }}
/bin/ollama run {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
volumes:
- name: ollama-data
{{- if .Values.persistentVolume.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.persistentVolume.existingClaim | default (printf "%s" (include "ollama.fullname" .)) }}
{{- else }}
emptyDir: { }
{{- end }}
{{- range .Values.ollama.models.create }}
{{- if .configMapRef }}
- name: {{ .name }}-config-model-volume
configMap:
name: {{ .configMapRef }}
items:
- key: {{ .configMapKeyRef }}
path: {{ .name }}
{{- end }}
{{- end }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.ollama.gpu.enabled .Values.tolerations }}
tolerations:
{{- if and .Values.ollama.gpu.enabled (or (eq .Values.ollama.gpu.type "nvidia") (not .Values.ollama.gpu.type)) }}
- key: "{{(.Values.ollama.gpu.nvidiaResource | default "nvidia.com/gpu")}}"
operator: Exists
effect: NoSchedule
{{- end }}
{{- with .Values.tolerations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,33 @@
{{- if (and .Values.persistentVolume.enabled (not .Values.persistentVolume.existingClaim)) -}}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
{{- if .Values.persistentVolume.annotations }}
annotations:
{{ toYaml .Values.persistentVolume.annotations | indent 4 }}
{{- end }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
name: {{ template "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
spec:
accessModes:
{{ toYaml .Values.persistentVolume.accessModes | indent 4 }}
{{- if .Values.persistentVolume.storageClass }}
{{- if (eq "-" .Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
{{- if .Values.persistentVolume.volumeMode }}
volumeMode: "{{ .Values.persistentVolume.volumeMode }}"
{{- end }}
{{- if .Values.persistentVolume.volumeName }}
volumeName: "{{ .Values.persistentVolume.volumeName }}"
{{- end }}
resources:
requests:
storage: "{{ .Values.persistentVolume.size }}"
{{- end -}}

View File

@ -0,0 +1,19 @@
{{- if and .Values.ollama.gpu.enabled .Values.ollama.gpu.draEnabled (not .Values.ollama.gpu.draExistingClaimTemplate) -}}
---
{{- if semverCompare ">=1.34-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: resource.k8s.io/v1
{{- else }}
apiVersion: resource.k8s.io/v1beta1
{{- end }}
kind: ResourceClaimTemplate
metadata:
name: {{ template "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
spec:
spec:
devices:
requests:
- name: gpu
deviceClassName: {{ .Values.ollama.gpu.draDriverClass }}
count: {{(.Values.ollama.gpu.number | default 1)}}
{{- end -}}

View File

@ -0,0 +1,32 @@
---
{{- if not .Values.knative.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "ollama.fullname" . }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.service.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
{{- if contains "NodePort" .Values.service.type }}
nodePort: {{ .Values.service.nodePort }}
{{- end }}
{{- if .Values.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.service.loadBalancerIP | quote }}
{{- end }}
selector:
{{- include "ollama.selectorLabels" . | nindent 4 }}
{{- end }}

View File

@ -0,0 +1,15 @@
{{- if .Values.serviceAccount.create -}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "ollama.serviceAccountName" . }}
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}

View File

@ -0,0 +1,25 @@
---
{{- if .Values.tests.enabled }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "ollama.fullname" . }}-test-connection"
namespace: {{ include "ollama.namespace" . }}
labels:
{{- include "ollama.labels" . | nindent 4 }}
{{- with .Values.tests.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
"helm.sh/hook": test
{{- with .Values.tests.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "ollama.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
{{ end }}