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

[v3.0.0] Major Version - PVC updates and sidecars #34

Merged
merged 4 commits into from
Dec 30, 2023
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
75 changes: 54 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ cat <<EOF > values.yaml
replicaCount: 1

deployment:
image: quay.io/go-skynet/local-ai:latest
image:
repository: quay.io/go-skynet/local-ai # Example: "docker.io/myapp"
tag: latest
env:
threads: 4
context_size: 512
modelsPath: "/models"
download_model:
# To use cloud provided (eg AWS) image, provide it like: 1234356789.dkr.ecr.us-REGION-X.amazonaws.com/busybox
image: busybox
prompt_templates:
# To use cloud provided (eg AWS) image, provide it like: 1234356789.dkr.ecr.us-REGION-X.amazonaws.com/busybox
image: busybox
pullPolicy: IfNotPresent
imagePullSecrets: []
# - name: secret-names

resources:
{}
Expand Down Expand Up @@ -50,31 +61,51 @@ models:
# The list of URLs to download models from
# Note: the name of the file will be the name of the loaded model
list:
- url: "https://gpt4all.io/models/ggml-gpt4all-j.bin"
# - url: "https://gpt4all.io/models/ggml-gpt4all-j.bin"
# basicAuth: base64EncodedCredentials

# Persistent storage for models and prompt templates.
# PVC and HostPath are mutually exclusive. If both are enabled,
# PVC configuration takes precedence. If neither are enabled, ephemeral
# storage is used.
persistence:
pvc:
enabled: false
size: 6Gi
accessModes:
- ReadWriteOnce

annotations: {}

# Optional
storageClass: ~

hostPath:
enabled: false
path: "/models"
initContainers: []
# Example:
# - name: my-init-container
# image: my-init-image
# imagePullPolicy: IfNotPresent
# command: ["/bin/sh", "-c", "echo init"]
# volumeMounts:
# - name: my-volume
# mountPath: /path/to/mount

sidecarContainers: []
# Example:
# - name: my-sidecar-container
# image: my-sidecar-image
# imagePullPolicy: IfNotPresent
# ports:
# - containerPort: 1234

# Persistent storage for models and prompt templates.
# PVC and HostPath are mutually exclusive. If both are enabled,
# PVC configuration takes precedence. If neither are enabled, ephemeral
# storage is used.
persistence:
models:
enabled: true
annotations: {}
storageClass: longhorn
accessModes: ReadWriteMany
size: 100Gi
globalMount: /models
images:
enabled: true
annotations: {}
storageClass: longhorn
accessModes: ReadWriteMany
size: 5Gi
globalMount: /tmp/generated/images

service:
type: ClusterIP
# If deferring to an internal only load balancer
# externalTrafficPolicy: Local
port: 80
annotations: {}
# If using an AWS load balancer, you'll need to override the default 60s load balancer idle timeout
Expand Down Expand Up @@ -103,6 +134,8 @@ tolerations: []

affinity: {}



```
Install the LocalAI chart:
```bash
Expand Down
2 changes: 1 addition & 1 deletion charts/local-ai/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ appVersion: 1.40
description: A Helm chart for deploying LocalAI to a Kubernetes cluster
name: local-ai
type: application
version: 2.1.3
version: 3.0.0
23 changes: 23 additions & 0 deletions charts/local-ai/templates/_pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- define "local-ai.pvc" }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ .name }}
namespace: {{ .namespace | quote }}
labels: {{ include "local-ai.labels" .labels | nindent 4 }}
{{- with .annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .storageClass }}
storageClassName: {{ . }}
{{- end }}
accessModes:
{{- range .accessModes }}
- {{ . | quote }}
{{- end }}
resources:
requests:
storage: {{ .size | quote }}
{{- end }}
171 changes: 121 additions & 50 deletions charts/local-ai/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,33 @@ spec:
checksum/config-prompt-templates: {{ include (print $.Template.BasePath "/configmap-prompt-templates.yaml") . | sha256sum }}
{{- end }}
spec:
{{- with .Values.deployment.imagePullSecrets }}
{{- with .Values.deployment.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
initContainers:
# Additional initContainers from values.yaml
{{- range .Values.initContainers }}
- name: {{ .name }}
image: {{ .image }}
imagePullPolicy: {{ .imagePullPolicy }}
command: {{ .command }}
args: {{ .args | default list }}
env:
{{- toYaml .env | nindent 12 }}
resources:
{{- toYaml .resources | nindent 12 }}
volumeMounts:
{{- toYaml .volumeMounts | nindent 12 }}
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
{{- end }}
{{- end }}
securityContext:
{{- toYaml .securityContext | nindent 12 }}
{{- end }}
{{- if .Values.promptTemplates }}
- name: prompt-templates
image: {{ .Values.deployment.prompt_templates.image }}
Expand All @@ -43,8 +65,12 @@ spec:
volumeMounts:
- mountPath: /prompt-templates
name: prompt-templates
- mountPath: /models
name: models
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
{{- end }}
{{- end }}
{{- end }}
- name: download-model
image: {{ .Values.deployment.download_model.image }}
Expand All @@ -55,74 +81,119 @@ spec:
MODEL_DIR={{ .Values.deployment.modelsPath }}
FORCE_DOWNLOAD={{ .Values.models.forceDownload }}
URLS="{{ $urls }}"
LOCK_DIR=/tmp/model-download-locks

mkdir -p "$MODEL_DIR"
mkdir -p "$LOCK_DIR"
mkdir -p "/tmp/generated/images"
mkdir -p "/tmp/generated/audio"
rm -rf "/models/lost+found"


# Split urls on commas
echo "$URLS" | awk -F, '{for (i=1; i<=NF; i++) print $i}' | while read -r line; do
url=$(echo "$line" | awk '{print $1}')
auth=$(echo "$line" | awk '{print $2}')
full_filename=$(basename "$url" .bin)
short_filename=$(echo "$full_filename" | cut -c1-20)
hash=$(echo "$full_filename" | sha256sum | cut -c1-12)
filename="${short_filename}_${hash}"
lockfile="$LOCK_DIR/$filename.lock"

if [ -n "$url" ]; then
filename=$(basename "$url" .bin)

if [ "$FORCE_DOWNLOAD" = false ] && [ -f "$MODEL_DIR/$filename" ]; then
echo "File $filename already exists. Skipping download."
continue
fi
if [ -e "$MODEL_DIR/$filename" ]; then
echo "File $filename already exists. Skipping download."
continue
fi

rm -f "$MODEL_DIR/$filename"
if [ -e "$lockfile" ]; then
echo "Another pod is downloading $filename. Waiting for download to complete."
while [ -e "$lockfile" ]; do sleep 1; done
continue
fi

echo "Downloading $filename"
touch "$lockfile"

if [ -n "$auth" ]; then
wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
else
wget "$url" -O "$MODEL_DIR/$filename"
fi
echo "Downloading $filename"
if [ -n "$auth" ]; then
wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
else
wget "$url" -O "$MODEL_DIR/$filename"
fi

if [ "$?" -ne 0 ]; then
echo "Download failed."
else
echo "Download completed."
fi
if [ "$?" -ne 0 ]; then
echo "Download failed."
rm -f "$lockfile"
exit 1
else
echo "Download completed."
rm -f "$lockfile"
fi
done
volumeMounts:
- mountPath: {{ .Values.deployment.modelsPath }}
name: models
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
{{- end }}
{{- end }}
containers:
# Sidecar containers from values.yaml
{{- range .Values.sidecarContainers }}
- name: {{ .name }}
image: {{ .image }}
imagePullPolicy: {{ .imagePullPolicy }}
command: {{ .command }}
args: {{ .args | default list }}
env:
{{- toYaml .env | nindent 12 }}
ports:
{{- toYaml .ports | nindent 12 }}
resources:
{{- toYaml .resources | nindent 12 }}
volumeMounts:
{{- toYaml .volumeMounts | nindent 12 }}
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
{{- end }}
{{- end }}
livenessProbe:
{{- toYaml .livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .readinessProbe | nindent 12 }}
securityContext:
{{- toYaml .securityContext | nindent 12 }}
{{- end }}
- name: {{ template "local-ai.fullname" . }}
image: {{ .Values.deployment.image }}
image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}"
imagePullPolicy: {{ .Values.deployment.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
{{- range $key, $value := .Values.deployment.env }}
- name: {{ $key | upper }}
value: {{ quote $value }}
{{- end }}
- name: MODELS_PATH
value: {{ .Values.deployment.modelsPath }}
{{- range $key, $value := .Values.deployment.env }}
- name: {{ $key | upper }}
value: {{ quote $value }}
{{- end }}
- name: MODELS_PATH
value: {{ .Values.deployment.modelsPath }}
volumeMounts:
- mountPath: {{ .Values.deployment.modelsPath }}
name: models
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
mountPath: {{ $pvc.globalMount | default (print "/" $key) }}
{{- end }}
{{- end }}
volumes:
{{- if .Values.models.persistence.pvc.enabled }}
- name: models
persistentVolumeClaim:
claimName: {{ template "local-ai.fullname" . }}
{{- else if .Values.models.persistence.hostPath.enabled }}
- name: models
hostPath:
path: {{ .Values.models.persistence.hostPath.path }}
{{- else }}
- name: models
emptyDir: {}
{{- end }}
- name: prompt-templates
configMap:
name: {{ template "local-ai.fullname" . }}-prompt-templates
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
- name: {{ $key }}
persistentVolumeClaim:
claimName: {{ printf "%s-%s" (include "local-ai.fullname" $) $key }}
{{- end }}
{{- end }}
- name: prompt-templates
configMap:
name: {{ template "local-ai.fullname" . }}-prompt-templates
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
23 changes: 0 additions & 23 deletions charts/local-ai/templates/pvc-models.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions charts/local-ai/templates/pvcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- range $key, $pvc := .Values.persistence }}
{{- if $pvc.enabled }}
{{- 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) }}
{{- end }}
{{- end }}
Loading