Skip to content

Commit

Permalink
make k8s work with remote chroma / mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeLalor committed Oct 18, 2024
1 parent cf80960 commit 8058ac8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ DOCKER_REPO_NAME ?= my-eidolon-project
VERSION := $(shell grep -m 1 '^version = ' pyproject.toml | awk -F '"' '{print $$2}')
WEBUI_TAG := latest
REQUIRED_ENVS := OPENAI_API_KEY
NAMESPACE ?= eidolon
NAMESPACE ?= default

.PHONY: docker-serve _docker-serve .env sync update docker-build docker-push pull-webui k8s-operator check-kubectl check-helm check-cluster-running verify-k8s-permissions check-install-operator k8s-serve k8s-env test
.PHONY: docker-serve _docker-serve .env sync update docker-build docker-push pull-webui k8s-operator check-kubectl check-helm check-cluster-running verify-k8s-permissions check-install-operator k8s-serve k8s-env k8s-mongo k8s-chroma test

ARGS ?=

Expand Down Expand Up @@ -122,6 +122,7 @@ check-install-operator:
echo "Eidolon operator is already installed."; \
fi


k8s-serve: k8s-server k8s-webui
@echo "Press Ctrl+C to exit"
@echo "------------------------------------------------------------------"
Expand All @@ -140,13 +141,26 @@ resources/machine.eidolon.yaml: Makefile
resources/machine.eidolon.yaml > resources/machine.eidolon.yaml.tmp && mv resources/machine.eidolon.yaml.tmp resources/machine.eidolon.yaml


k8s-server: check-cluster-running docker-build docker-push k8s-env resources/machine.eidolon.yaml
k8s-server: check-cluster-running docker-push k8s-env resources/machine.eidolon.yaml k8s-mongo k8s-chroma
@kubectl apply -f resources/ --namespace=$(NAMESPACE)
@kubectl apply -f k8s/eidolon-ext-service.yaml --namespace=$(NAMESPACE)
@echo "Waiting for eidolon-deployment to be ready..."
@kubectl rollout status deployment/eidolon-deployment --timeout=60s --namespace=$(NAMESPACE)
@echo "Server Deployment is ready."

k8s-mongo:
@kubectl apply -f k8s/mongo.yaml --namespace=$(NAMESPACE)
@echo "Waiting for mongo to be ready..."
@kubectl wait --for=condition=ready pod -l app=mongodb --timeout=60s --namespace=$(NAMESPACE)
@echo "Mongo Deployment is ready."

k8s-chroma:
@kubectl apply -f k8s/chroma.yaml --namespace=$(NAMESPACE)
@echo "Waiting for chroma to be ready..."
@kubectl wait --for=condition=ready pod -l app=chromadb --timeout=60s --namespace=$(NAMESPACE)
@kubectl rollout status deployment/chromadb --timeout=60s --namespace=$(NAMESPACE)
@echo "Chroma Deployment is ready."

k8s/webui.yaml: Makefile
@sed -e 's|image: docker.io/eidolonai/webui:.*|image: docker.io/eidolonai/webui:$(WEBUI_TAG)|' k8s/webui.yaml > k8s/webui.yaml.tmp && mv k8s/webui.yaml.tmp k8s/webui.yaml

Expand All @@ -170,7 +184,7 @@ k8s-env: create-namespace .env
docker-build: poetry.lock Dockerfile
@docker build -t $(DOCKER_REPO_NAME):latest .

docker-push:
docker-push: docker-build
@if [ -n "$(DOCKER_REPO_URL)" ]; then \
docker push $(DOCKER_REPO_NAME):latest; \
fi
Expand All @@ -193,4 +207,4 @@ pull-chroma:
fi

k8s-clean:
@kubectl delete -f resources/ -f k8s/eidolon-ext-service.yaml -f k8s/webui.yaml -n $(NAMESPACE)
@kubectl delete -f resources/ -f k8s/eidolon-ext-service.yaml -f k8s/webui.yaml -f k8s/mongo.yaml -f k8s/chroma.yaml -n $(NAMESPACE)
41 changes: 41 additions & 0 deletions k8s/chroma.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: chromadb
spec:
replicas: 1
selector:
matchLabels:
app: chromadb
template:
metadata:
labels:
app: chromadb
spec:
containers:
- name: chromadb
image: chromadb/chroma
env:
- name: CHROME_USER_DATA_DIR
value: /chromadb/data
ports:
- containerPort: 27017
volumeMounts:
- name: chromadb-data
mountPath: /chromadb/data
volumes:
- name: chromadb-data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: chromadb
spec:
selector:
app: chromadb
ports:
- protocol: TCP
port: 8000
targetPort: 8000
3 changes: 2 additions & 1 deletion k8s/get_service_url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ else
IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
fi

# Print the URL
# Ensure we only use the IPv4 address if multiple IPs are returned
IP=$(echo "$IP" | awk -F' ' '{print $1}')
echo "http://$IP:$NODE_PORT"
38 changes: 38 additions & 0 deletions k8s/mongo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongodb-data
mountPath: /data/db
volumes:
- name: mongodb-data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: mongo
spec:
selector:
app: mongodb
ports:
- protocol: TCP
port: 27017
targetPort: 27017

0 comments on commit 8058ac8

Please sign in to comment.