Skip to content

Commit 0e7f93d

Browse files
committed
add kubernetes support
1 parent 598913c commit 0e7f93d

16 files changed

Lines changed: 2921 additions & 0 deletions

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Unified Context-Engine image for Kubernetes deployment
2+
# Supports multiple roles: memory, indexer, watcher, llamacpp
3+
FROM python:3.11-slim
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
WORK_ROOTS="/work,/app"
8+
9+
# Install OS dependencies
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
11+
git \
12+
ca-certificates \
13+
curl \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Install Python dependencies for all services
17+
RUN pip install --no-cache-dir --upgrade \
18+
qdrant-client \
19+
fastembed \
20+
watchdog \
21+
onnxruntime \
22+
tokenizers \
23+
tree_sitter \
24+
tree_sitter_languages \
25+
mcp \
26+
fastmcp
27+
28+
# Copy scripts for all services
29+
COPY scripts /app/scripts
30+
31+
# Create directories
32+
WORKDIR /work
33+
34+
# Expose all necessary ports
35+
EXPOSE 8000 8001 8002 8003 18000 18001 18002 18003
36+
37+
# Default to memory server
38+
CMD ["python", "/app/scripts/mcp_memory_server.py"]

deploy/kubernetes/Makefile

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Context-Engine Kubernetes Deployment Makefile
2+
3+
# Configuration
4+
NAMESPACE ?= context-engine
5+
IMAGE_REGISTRY ?= context-engine
6+
IMAGE_TAG ?= latest
7+
8+
# Default target
9+
.PHONY: help
10+
help: ## Show this help message
11+
@echo "Context-Engine Kubernetes Deployment Commands"
12+
@echo ""
13+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
14+
15+
# Prerequisites
16+
.PHONY: check-kubectl
17+
check-kubectl: ## Check if kubectl is available and cluster is accessible
18+
@which kubectl > /dev/null || (echo "kubectl not found. Please install kubectl." && exit 1)
19+
@kubectl cluster-info > /dev/null || (echo "Cannot connect to Kubernetes cluster." && exit 1)
20+
@echo "✓ Kubernetes connection verified"
21+
22+
# Deployment targets
23+
.PHONY: deploy
24+
deploy: check-kubectl ## Deploy all Context-Engine services
25+
./deploy.sh --namespace $(NAMESPACE) --registry $(IMAGE_REGISTRY) --tag $(IMAGE_TAG)
26+
27+
.PHONY: deploy-core
28+
deploy-core: check-kubectl ## Deploy only core services (Qdrant + MCP servers)
29+
@echo "Deploying core services..."
30+
kubectl apply -f namespace.yaml
31+
kubectl apply -f configmap.yaml
32+
kubectl apply -f qdrant.yaml
33+
kubectl apply -f mcp-memory.yaml
34+
kubectl apply -f mcp-indexer.yaml
35+
36+
.PHONY: deploy-full
37+
deploy-full: check-kubectl ## Deploy all services including optional ones
38+
./deploy.sh --namespace $(NAMESPACE) --registry $(IMAGE_REGISTRY) --tag $(IMAGE_TAG) --deploy-ingress
39+
40+
.PHONY: deploy-minimal
41+
deploy-minimal: check-kubectl ## Deploy minimal setup (skip Llama.cpp and Ingress)
42+
./deploy.sh --namespace $(NAMESPACE) --registry $(IMAGE_REGISTRY) --tag $(IMAGE_TAG) --skip-llamacpp
43+
44+
# Kustomize targets
45+
.PHONY: kustomize-build
46+
kustomize-build: ## Build manifests with Kustomize
47+
kustomize build .
48+
49+
.PHONY: kustomize-apply
50+
kustomize-apply: check-kubectl ## Apply manifests with Kustomize
51+
kustomize build . | kubectl apply -f -
52+
53+
.PHONY: kustomize-delete
54+
kustomize-delete: check-kubectl ## Delete manifests with Kustomize
55+
kustomize build . | kubectl delete -f -
56+
57+
# Management targets
58+
.PHONY: status
59+
status: check-kubectl ## Show deployment status
60+
@echo "=== Namespace Status ==="
61+
kubectl get namespace $(NAMESPACE) || echo "Namespace $(NAMESPACE) not found"
62+
@echo ""
63+
@echo "=== Pods ==="
64+
kubectl get pods -n $(NAMESPACE) -o wide || echo "No pods found"
65+
@echo ""
66+
@echo "=== Services ==="
67+
kubectl get services -n $(NAMESPACE) || echo "No services found"
68+
@echo ""
69+
@echo "=== Deployments ==="
70+
kubectl get deployments -n $(NAMESPACE) || echo "No deployments found"
71+
@echo ""
72+
@echo "=== StatefulSets ==="
73+
kubectl get statefulsets -n $(NAMESPACE) || echo "No statefulsets found"
74+
@echo ""
75+
@echo "=== PersistentVolumeClaims ==="
76+
kubectl get pvc -n $(NAMESPACE) || echo "No PVCs found"
77+
@echo ""
78+
@echo "=== Jobs ==="
79+
kubectl get jobs -n $(NAMESPACE) || echo "No jobs found"
80+
81+
.PHONY: logs
82+
logs: check-kubectl ## Show logs for all services
83+
@echo "=== Qdrant Logs ==="
84+
kubectl logs -f statefulset/qdrant -n $(NAMESPACE) --tail=50 || echo "Qdrant logs not available"
85+
86+
.PHONY: logs-service
87+
logs-service: check-kubectl ## Show logs for specific service (usage: make logs-service SERVICE=mcp-memory)
88+
@if [ -z "$(SERVICE)" ]; then echo "Usage: make logs-service SERVICE=<service-name>"; exit 1; fi
89+
kubectl logs -f deployment/$(SERVICE) -n $(NAMESPACE) --tail=100 || kubectl logs -f statefulset/$(SERVICE) -n $(NAMESPACE) --tail=100 || kubectl logs -f job/$(SERVICE) -n $(NAMESPACE) --tail=100 || echo "Service $(SERVICE) not found"
90+
91+
.PHONY: shell
92+
shell: check-kubectl ## Get a shell in a running pod (usage: make shell POD=mcp-memory-xxx)
93+
@if [ -z "$(POD)" ]; then echo "Usage: make shell POD=<pod-name>"; echo "Available pods:"; kubectl get pods -n $(NAMESPACE); exit 1; fi
94+
kubectl exec -it $(POD) -n $(NAMESPACE) -- /bin/bash || kubectl exec -it $(POD) -n $(NAMESPACE) -- /bin/sh
95+
96+
# Cleanup targets
97+
.PHONY: cleanup
98+
cleanup: check-kubectl ## Remove all Context-Engine resources
99+
./cleanup.sh --namespace $(NAMESPACE)
100+
101+
.PHONY: clean-force
102+
clean-force: check-kubectl ## Force cleanup without confirmation
103+
./cleanup.sh --namespace $(NAMESPACE) --force
104+
105+
# Development targets
106+
.PHONY: restart
107+
restart: check-kubectl ## Restart all deployments
108+
kubectl rollout restart deployment -n $(NAMESPACE)
109+
kubectl rollout restart statefulset -n $(NAMESPACE)
110+
111+
.PHONY: restart-service
112+
restart-service: check-kubectl ## Restart specific service (usage: make restart-service SERVICE=mcp-memory)
113+
@if [ -z "$(SERVICE)" ]; then echo "Usage: make restart-service SERVICE=<service-name>"; exit 1; fi
114+
kubectl rollout restart deployment/$(SERVICE) -n $(NAMESPACE) || kubectl rollout restart statefulset/$(SERVICE) -n $(NAMESPACE)
115+
116+
.PHONY: scale
117+
scale: check-kubectl ## Scale a deployment (usage: make scale SERVICE=mcp-memory REPLICAS=3)
118+
@if [ -z "$(SERVICE)" ] || [ -z "$(REPLICAS)" ]; then echo "Usage: make scale SERVICE=<service-name> REPLICAS=<number>"; exit 1; fi
119+
kubectl scale deployment $(SERVICE) -n $(NAMESPACE) --replicas=$(REPLICAS)
120+
121+
# Port forwarding targets
122+
.PHONY: port-forward
123+
port-forward: check-kubectl ## Port forward all services
124+
@echo "Opening port forwards in background..."
125+
@kubectl port-forward -n $(NAMESPACE) service/qdrant 6333:6333 &
126+
@kubectl port-forward -n $(NAMESPACE) service/mcp-memory 8000:8000 &
127+
@kubectl port-forward -n $(NAMESPACE) service/mcp-indexer 8001:8001 &
128+
@echo "Port forwards started. Use 'make stop-port-forward' to stop."
129+
130+
.PHONY: port-forward-service
131+
port-forward-service: check-kubectl ## Port forward specific service (usage: make port-forward-service SERVICE=qdrant LOCAL=6333 REMOTE=6333)
132+
@if [ -z "$(SERVICE)" ] || [ -z "$(LOCAL)" ] || [ -z "$(REMOTE)" ]; then echo "Usage: make port-forward-service SERVICE=<service-name> LOCAL=<local-port> REMOTE=<remote-port>"; exit 1; fi
133+
kubectl port-forward -n $(NAMESPACE) service/$(SERVICE) $(LOCAL):$(REMOTE)
134+
135+
.PHONY: stop-port-forward
136+
stop-port-forward: ## Stop all port forwards
137+
pkill -f "kubectl port-forward" || echo "No port forwards found"
138+
139+
# Build and push targets
140+
.PHONY: build-image
141+
build-image: ## Build Docker image
142+
docker build -t $(IMAGE_REGISTRY)/context-engine:$(IMAGE_TAG) ../../
143+
144+
.PHONY: push-image
145+
push-image: build-image ## Push Docker image to registry
146+
docker push $(IMAGE_REGISTRY)/context-engine:$(IMAGE_TAG)
147+
148+
# Test targets
149+
.PHONY: test-connection
150+
test-connection: check-kubectl ## Test connectivity to all services
151+
@echo "Testing service connectivity..."
152+
@echo "Qdrant:"
153+
@kubectl run qdrant-test --image=curlimages/curl --rm -i --restart=Never -n $(NAMESPACE) -- curl -f http://qdrant.$(NAMESPACE).svc.cluster.local:6333/health || echo "Qdrant test failed"
154+
@echo "MCP Memory:"
155+
@kubectl run memory-test --image=curlimages/curl --rm -i --restart=Never -n $(NAMESPACE) -- curl -f http://mcp-memory.$(NAMESPACE).svc.cluster.local:18000/health || echo "MCP Memory test failed"
156+
@echo "MCP Indexer:"
157+
@kubectl run indexer-test --image=curlimages/curl --rm -i --restart=Never -n $(NAMESPACE) -- curl -f http://mcp-indexer.$(NAMESPACE).svc.cluster.local:18001/health || echo "MCP Indexer test failed"
158+
159+
# Configuration targets
160+
.PHONY: show-config
161+
show-config: ## Show current configuration
162+
@echo "Configuration:"
163+
@echo " NAMESPACE: $(NAMESPACE)"
164+
@echo " IMAGE_REGISTRY: $(IMAGE_REGISTRY)"
165+
@echo " IMAGE_TAG: $(IMAGE_TAG)"
166+
@echo ""
167+
@echo "Quick start commands:"
168+
@echo " make deploy # Deploy all services"
169+
@echo " make status # Show deployment status"
170+
@echo " make logs-service SERVICE=mcp-memory # Show logs"
171+
@echo " make cleanup # Remove everything"
172+
173+
.PHONY: show-urls
174+
show-urls: check-kubectl ## Show access URLs for services
175+
@echo "Service URLs (via NodePort):"
176+
@echo " Qdrant: http://<node-ip>:30333"
177+
@echo " MCP Memory (SSE): http://<node-ip>:30800"
178+
@echo " MCP Indexer (SSE): http://<node-ip>:30802"
179+
@echo " MCP Memory (HTTP): http://<node-ip>:30804"
180+
@echo " MCP Indexer (HTTP): http://<node-ip>:30806"
181+
@echo " Llama.cpp: http://<node-ip>:30808"
182+
@echo ""
183+
@echo "Service URLs (via port-forward):"
184+
@echo " make port-forward # Then access via localhost ports"
185+
186+
# Advanced targets
187+
.PHONY: watch-deployment
188+
watch-deployment: check-kubectl ## Watch deployment progress
189+
watch kubectl get pods,services,deployments -n $(NAMESPACE)
190+
191+
.PHONY: describe-service
192+
describe-service: check-kubectl ## Describe a service (usage: make describe-service SERVICE=mcp-memory)
193+
@if [ -z "$(SERVICE)" ]; then echo "Usage: make describe-service SERVICE=<service-name>"; echo "Available services:"; kubectl get services -n $(NAMESPACE); exit 1; fi
194+
kubectl describe service $(SERVICE) -n $(NAMESPACE)
195+
196+
.PHONY: events
197+
events: check-kubectl ## Show recent events
198+
kubectl get events -n $(NAMESPACE) --sort-by=.metadata.creationTimestamp
199+

0 commit comments

Comments
 (0)