Skip to content

Commit 370e51f

Browse files
authored
Merge pull request #34 from lenaxia/main
[v3.0.0] Major Version - PVC updates and sidecars
2 parents 649ea8f + 28ab835 commit 370e51f

File tree

7 files changed

+244
-118
lines changed

7 files changed

+244
-118
lines changed

README.md

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ cat <<EOF > values.yaml
1313
replicaCount: 1
1414
1515
deployment:
16-
image: quay.io/go-skynet/local-ai:latest
16+
image:
17+
repository: quay.io/go-skynet/local-ai # Example: "docker.io/myapp"
18+
tag: latest
1719
env:
1820
threads: 4
1921
context_size: 512
2022
modelsPath: "/models"
23+
download_model:
24+
# To use cloud provided (eg AWS) image, provide it like: 1234356789.dkr.ecr.us-REGION-X.amazonaws.com/busybox
25+
image: busybox
26+
prompt_templates:
27+
# To use cloud provided (eg AWS) image, provide it like: 1234356789.dkr.ecr.us-REGION-X.amazonaws.com/busybox
28+
image: busybox
29+
pullPolicy: IfNotPresent
30+
imagePullSecrets: []
31+
# - name: secret-names
2132
2233
resources:
2334
{}
@@ -50,31 +61,51 @@ models:
5061
# The list of URLs to download models from
5162
# Note: the name of the file will be the name of the loaded model
5263
list:
53-
- url: "https://gpt4all.io/models/ggml-gpt4all-j.bin"
64+
# - url: "https://gpt4all.io/models/ggml-gpt4all-j.bin"
5465
# basicAuth: base64EncodedCredentials
5566
56-
# Persistent storage for models and prompt templates.
57-
# PVC and HostPath are mutually exclusive. If both are enabled,
58-
# PVC configuration takes precedence. If neither are enabled, ephemeral
59-
# storage is used.
60-
persistence:
61-
pvc:
62-
enabled: false
63-
size: 6Gi
64-
accessModes:
65-
- ReadWriteOnce
66-
67-
annotations: {}
68-
69-
# Optional
70-
storageClass: ~
71-
72-
hostPath:
73-
enabled: false
74-
path: "/models"
67+
initContainers: []
68+
# Example:
69+
# - name: my-init-container
70+
# image: my-init-image
71+
# imagePullPolicy: IfNotPresent
72+
# command: ["/bin/sh", "-c", "echo init"]
73+
# volumeMounts:
74+
# - name: my-volume
75+
# mountPath: /path/to/mount
76+
77+
sidecarContainers: []
78+
# Example:
79+
# - name: my-sidecar-container
80+
# image: my-sidecar-image
81+
# imagePullPolicy: IfNotPresent
82+
# ports:
83+
# - containerPort: 1234
84+
85+
# Persistent storage for models and prompt templates.
86+
# PVC and HostPath are mutually exclusive. If both are enabled,
87+
# PVC configuration takes precedence. If neither are enabled, ephemeral
88+
# storage is used.
89+
persistence:
90+
models:
91+
enabled: true
92+
annotations: {}
93+
storageClass: longhorn
94+
accessModes: ReadWriteMany
95+
size: 100Gi
96+
globalMount: /models
97+
images:
98+
enabled: true
99+
annotations: {}
100+
storageClass: longhorn
101+
accessModes: ReadWriteMany
102+
size: 5Gi
103+
globalMount: /tmp/generated/images
75104
76105
service:
77106
type: ClusterIP
107+
# If deferring to an internal only load balancer
108+
# externalTrafficPolicy: Local
78109
port: 80
79110
annotations: {}
80111
# If using an AWS load balancer, you'll need to override the default 60s load balancer idle timeout
@@ -103,6 +134,8 @@ tolerations: []
103134
104135
affinity: {}
105136
137+
138+
106139
```
107140
Install the LocalAI chart:
108141
```bash

charts/local-ai/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ appVersion: 1.40
33
description: A Helm chart for deploying LocalAI to a Kubernetes cluster
44
name: local-ai
55
type: application
6-
version: 2.1.3
6+
version: 3.0.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{- define "local-ai.pvc" }}
2+
kind: PersistentVolumeClaim
3+
apiVersion: v1
4+
metadata:
5+
name: {{ .name }}
6+
namespace: {{ .namespace | quote }}
7+
labels: {{ include "local-ai.labels" .labels | nindent 4 }}
8+
{{- with .annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
{{- with .storageClass }}
14+
storageClassName: {{ . }}
15+
{{- end }}
16+
accessModes:
17+
{{- range .accessModes }}
18+
- {{ . | quote }}
19+
{{- end }}
20+
resources:
21+
requests:
22+
storage: {{ .size | quote }}
23+
{{- end }}

charts/local-ai/templates/deployment.yaml

Lines changed: 121 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,33 @@ spec:
2727
checksum/config-prompt-templates: {{ include (print $.Template.BasePath "/configmap-prompt-templates.yaml") . | sha256sum }}
2828
{{- end }}
2929
spec:
30-
{{- with .Values.deployment.imagePullSecrets }}
30+
{{- with .Values.deployment.imagePullSecrets }}
3131
imagePullSecrets:
3232
{{- toYaml . | nindent 8 }}
33-
{{- end }}
33+
{{- end }}
3434
initContainers:
35+
# Additional initContainers from values.yaml
36+
{{- range .Values.initContainers }}
37+
- name: {{ .name }}
38+
image: {{ .image }}
39+
imagePullPolicy: {{ .imagePullPolicy }}
40+
command: {{ .command }}
41+
args: {{ .args | default list }}
42+
env:
43+
{{- toYaml .env | nindent 12 }}
44+
resources:
45+
{{- toYaml .resources | nindent 12 }}
46+
volumeMounts:
47+
{{- toYaml .volumeMounts | nindent 12 }}
48+
{{- range $key, $pvc := .Values.persistence }}
49+
{{- if $pvc.enabled }}
50+
- name: {{ $key }}
51+
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
52+
{{- end }}
53+
{{- end }}
54+
securityContext:
55+
{{- toYaml .securityContext | nindent 12 }}
56+
{{- end }}
3557
{{- if .Values.promptTemplates }}
3658
- name: prompt-templates
3759
image: {{ .Values.deployment.prompt_templates.image }}
@@ -43,8 +65,12 @@ spec:
4365
volumeMounts:
4466
- mountPath: /prompt-templates
4567
name: prompt-templates
46-
- mountPath: /models
47-
name: models
68+
{{- range $key, $pvc := .Values.persistence }}
69+
{{- if $pvc.enabled }}
70+
- name: {{ $key }}
71+
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
72+
{{- end }}
73+
{{- end }}
4874
{{- end }}
4975
- name: download-model
5076
image: {{ .Values.deployment.download_model.image }}
@@ -55,74 +81,119 @@ spec:
5581
MODEL_DIR={{ .Values.deployment.modelsPath }}
5682
FORCE_DOWNLOAD={{ .Values.models.forceDownload }}
5783
URLS="{{ $urls }}"
84+
LOCK_DIR=/tmp/model-download-locks
5885
5986
mkdir -p "$MODEL_DIR"
87+
mkdir -p "$LOCK_DIR"
88+
mkdir -p "/tmp/generated/images"
89+
mkdir -p "/tmp/generated/audio"
90+
rm -rf "/models/lost+found"
91+
6092
61-
# Split urls on commas
6293
echo "$URLS" | awk -F, '{for (i=1; i<=NF; i++) print $i}' | while read -r line; do
6394
url=$(echo "$line" | awk '{print $1}')
6495
auth=$(echo "$line" | awk '{print $2}')
96+
full_filename=$(basename "$url" .bin)
97+
short_filename=$(echo "$full_filename" | cut -c1-20)
98+
hash=$(echo "$full_filename" | sha256sum | cut -c1-12)
99+
filename="${short_filename}_${hash}"
100+
lockfile="$LOCK_DIR/$filename.lock"
65101
66-
if [ -n "$url" ]; then
67-
filename=$(basename "$url" .bin)
68-
69-
if [ "$FORCE_DOWNLOAD" = false ] && [ -f "$MODEL_DIR/$filename" ]; then
70-
echo "File $filename already exists. Skipping download."
71-
continue
72-
fi
102+
if [ -e "$MODEL_DIR/$filename" ]; then
103+
echo "File $filename already exists. Skipping download."
104+
continue
105+
fi
73106
74-
rm -f "$MODEL_DIR/$filename"
107+
if [ -e "$lockfile" ]; then
108+
echo "Another pod is downloading $filename. Waiting for download to complete."
109+
while [ -e "$lockfile" ]; do sleep 1; done
110+
continue
111+
fi
75112
76-
echo "Downloading $filename"
113+
touch "$lockfile"
77114
78-
if [ -n "$auth" ]; then
79-
wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
80-
else
81-
wget "$url" -O "$MODEL_DIR/$filename"
82-
fi
115+
echo "Downloading $filename"
116+
if [ -n "$auth" ]; then
117+
wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
118+
else
119+
wget "$url" -O "$MODEL_DIR/$filename"
120+
fi
83121
84-
if [ "$?" -ne 0 ]; then
85-
echo "Download failed."
86-
else
87-
echo "Download completed."
88-
fi
122+
if [ "$?" -ne 0 ]; then
123+
echo "Download failed."
124+
rm -f "$lockfile"
125+
exit 1
126+
else
127+
echo "Download completed."
128+
rm -f "$lockfile"
89129
fi
90130
done
91131
volumeMounts:
92-
- mountPath: {{ .Values.deployment.modelsPath }}
93-
name: models
132+
{{- range $key, $pvc := .Values.persistence }}
133+
{{- if $pvc.enabled }}
134+
- name: {{ $key }}
135+
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
136+
{{- end }}
137+
{{- end }}
94138
containers:
139+
# Sidecar containers from values.yaml
140+
{{- range .Values.sidecarContainers }}
141+
- name: {{ .name }}
142+
image: {{ .image }}
143+
imagePullPolicy: {{ .imagePullPolicy }}
144+
command: {{ .command }}
145+
args: {{ .args | default list }}
146+
env:
147+
{{- toYaml .env | nindent 12 }}
148+
ports:
149+
{{- toYaml .ports | nindent 12 }}
150+
resources:
151+
{{- toYaml .resources | nindent 12 }}
152+
volumeMounts:
153+
{{- toYaml .volumeMounts | nindent 12 }}
154+
{{- range $key, $pvc := .Values.persistence }}
155+
{{- if $pvc.enabled }}
156+
- name: {{ $key }}
157+
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
158+
{{- end }}
159+
{{- end }}
160+
livenessProbe:
161+
{{- toYaml .livenessProbe | nindent 12 }}
162+
readinessProbe:
163+
{{- toYaml .readinessProbe | nindent 12 }}
164+
securityContext:
165+
{{- toYaml .securityContext | nindent 12 }}
166+
{{- end }}
95167
- name: {{ template "local-ai.fullname" . }}
96-
image: {{ .Values.deployment.image }}
168+
image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}"
97169
imagePullPolicy: {{ .Values.deployment.pullPolicy }}
98170
resources:
99171
{{- toYaml .Values.resources | nindent 12 }}
100172
env:
101-
{{- range $key, $value := .Values.deployment.env }}
102-
- name: {{ $key | upper }}
103-
value: {{ quote $value }}
104-
{{- end }}
105-
- name: MODELS_PATH
106-
value: {{ .Values.deployment.modelsPath }}
173+
{{- range $key, $value := .Values.deployment.env }}
174+
- name: {{ $key | upper }}
175+
value: {{ quote $value }}
176+
{{- end }}
177+
- name: MODELS_PATH
178+
value: {{ .Values.deployment.modelsPath }}
107179
volumeMounts:
108-
- mountPath: {{ .Values.deployment.modelsPath }}
109-
name: models
180+
{{- range $key, $pvc := .Values.persistence }}
181+
{{- if $pvc.enabled }}
182+
- name: {{ $key }}
183+
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
184+
{{- end }}
185+
{{- end }}
110186
volumes:
111-
{{- if .Values.models.persistence.pvc.enabled }}
112-
- name: models
113-
persistentVolumeClaim:
114-
claimName: {{ template "local-ai.fullname" . }}
115-
{{- else if .Values.models.persistence.hostPath.enabled }}
116-
- name: models
117-
hostPath:
118-
path: {{ .Values.models.persistence.hostPath.path }}
119-
{{- else }}
120-
- name: models
121-
emptyDir: {}
122-
{{- end }}
123-
- name: prompt-templates
124-
configMap:
125-
name: {{ template "local-ai.fullname" . }}-prompt-templates
187+
{{- range $key, $pvc := .Values.persistence }}
188+
{{- if $pvc.enabled }}
189+
- name: {{ $key }}
190+
persistentVolumeClaim:
191+
claimName: {{ printf "%s-%s" (include "local-ai.fullname" $) $key }}
192+
{{- end }}
193+
{{- end }}
194+
- name: prompt-templates
195+
configMap:
196+
name: {{ template "local-ai.fullname" . }}-prompt-templates
126197
{{- with .Values.nodeSelector }}
127198
nodeSelector:
128199
{{- toYaml . | nindent 8 }}

charts/local-ai/templates/pvc-models.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{- range $key, $pvc := .Values.persistence }}
2+
{{- if $pvc.enabled }}
3+
{{- include "local-ai.pvc" (dict "name" (printf "%s-%s" (include "local-ai.fullname" $) $key) "namespace" $.Release.Namespace "labels" (include "local-ai.labels" $) "annotations" $pvc.annotations "storageClass" $pvc.storageClass "accessModes" $pvc.accessModes "size" $pvc.size) }}
4+
{{- end }}
5+
{{- end }}

0 commit comments

Comments
 (0)