From 1b06a5a3e0b8d8e258404461321482963f72ceaa Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 23 May 2024 18:23:01 +0100
Subject: [PATCH 1/2] feat: k8s deployment
---
k8s/deployments/docsgpt-deploy.yaml | 98 +++++++++++++++++++++++++++++
k8s/deployments/mongo-deploy.yaml | 46 ++++++++++++++
k8s/deployments/qdrant-deploy.yaml | 46 ++++++++++++++
k8s/deployments/redis-deploy.yaml | 26 ++++++++
k8s/docsgpt-secrets.yaml | 15 +++++
k8s/services/docsgpt-service.yaml | 25 ++++++++
k8s/services/mongo-service.yaml | 12 ++++
k8s/services/qdrant-service.yaml | 12 ++++
k8s/services/redis-service.yaml | 12 ++++
9 files changed, 292 insertions(+)
create mode 100644 k8s/deployments/docsgpt-deploy.yaml
create mode 100644 k8s/deployments/mongo-deploy.yaml
create mode 100644 k8s/deployments/qdrant-deploy.yaml
create mode 100644 k8s/deployments/redis-deploy.yaml
create mode 100644 k8s/docsgpt-secrets.yaml
create mode 100644 k8s/services/docsgpt-service.yaml
create mode 100644 k8s/services/mongo-service.yaml
create mode 100644 k8s/services/qdrant-service.yaml
create mode 100644 k8s/services/redis-service.yaml
diff --git a/k8s/deployments/docsgpt-deploy.yaml b/k8s/deployments/docsgpt-deploy.yaml
new file mode 100644
index 00000000..1d0b86a3
--- /dev/null
+++ b/k8s/deployments/docsgpt-deploy.yaml
@@ -0,0 +1,98 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: docsgpt-api
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: docsgpt-api
+ template:
+ metadata:
+ labels:
+ app: docsgpt-api
+ spec:
+ containers:
+ - name: docsgpt-api
+ image: arc53/docsgpt
+ ports:
+ - containerPort: 7091
+ resources:
+ limits:
+ memory: "4Gi"
+ cpu: "2"
+ requests:
+ memory: "2Gi"
+ cpu: "1"
+ envFrom:
+ - secretRef:
+ name: docsgpt-secrets
+ env:
+ - name: FLASK_APP
+ value: "application/app.py"
+ - name: DEPLOYMENT_TYPE
+ value: "cloud"
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: docsgpt-worker
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: docsgpt-worker
+ template:
+ metadata:
+ labels:
+ app: docsgpt-worker
+ spec:
+ containers:
+ - name: docsgpt-worker
+ image: arc53/docsgpt
+ command: ["celery", "-A", "application.app.celery", "worker", "-l", "INFO", "-n", "worker.%h"]
+ resources:
+ limits:
+ memory: "4Gi"
+ cpu: "2"
+ requests:
+ memory: "2Gi"
+ cpu: "1"
+ envFrom:
+ - secretRef:
+ name: docsgpt-secrets
+ env:
+ - name: API_URL
+ value: "BACKEND-URL"
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: docsgpt-frontend
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: docsgpt-frontend
+ template:
+ metadata:
+ labels:
+ app: docsgpt-frontend
+ spec:
+ containers:
+ - name: docsgpt-frontend
+ image: arc53/docsgpt-fe
+ ports:
+ - containerPort: 5173
+ resources:
+ limits:
+ memory: "1Gi"
+ cpu: "1"
+ requests:
+ memory: "256Mi"
+ cpu: "100m"
+ env:
+ - name: VITE_API_HOST
+ value: "BACKEND-URL"
+ - name: VITE_API_STREAMING
+ value: "true"
\ No newline at end of file
diff --git a/k8s/deployments/mongo-deploy.yaml b/k8s/deployments/mongo-deploy.yaml
new file mode 100644
index 00000000..1ab55295
--- /dev/null
+++ b/k8s/deployments/mongo-deploy.yaml
@@ -0,0 +1,46 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: mongodb-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 10Gi # Adjust size as needed
+
+---
+
+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:latest
+ ports:
+ - containerPort: 27017
+ resources:
+ limits:
+ memory: "1Gi"
+ cpu: "0.5"
+ requests:
+ memory: "512Mi"
+ cpu: "250m"
+ volumeMounts:
+ - name: mongodb-data
+ mountPath: /data/db
+ volumes:
+ - name: mongodb-data
+ persistentVolumeClaim:
+ claimName: mongodb-pvc
\ No newline at end of file
diff --git a/k8s/deployments/qdrant-deploy.yaml b/k8s/deployments/qdrant-deploy.yaml
new file mode 100644
index 00000000..70937b17
--- /dev/null
+++ b/k8s/deployments/qdrant-deploy.yaml
@@ -0,0 +1,46 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: qdrant-pvc
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 10Gi
+
+---
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: qdrant
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: qdrant
+ template:
+ metadata:
+ labels:
+ app: qdrant
+ spec:
+ containers:
+ - name: qdrant
+ image: qdrant/qdrant:latest
+ ports:
+ - containerPort: 6333
+ resources:
+ limits:
+ memory: "2Gi" # Adjust based on your needs
+ cpu: "1" # Adjust based on your needs
+ requests:
+ memory: "1Gi" # Adjust based on your needs
+ cpu: "500m" # Adjust based on your needs
+ volumeMounts:
+ - name: qdrant-data
+ mountPath: /qdrant/storage
+ volumes:
+ - name: qdrant-data
+ persistentVolumeClaim:
+ claimName: qdrant-pvc
\ No newline at end of file
diff --git a/k8s/deployments/redis-deploy.yaml b/k8s/deployments/redis-deploy.yaml
new file mode 100644
index 00000000..e2728961
--- /dev/null
+++ b/k8s/deployments/redis-deploy.yaml
@@ -0,0 +1,26 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: redis
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: redis
+ template:
+ metadata:
+ labels:
+ app: redis
+ spec:
+ containers:
+ - name: redis
+ image: redis:latest
+ ports:
+ - containerPort: 6379
+ resources:
+ limits:
+ memory: "1Gi"
+ cpu: "0.5"
+ requests:
+ memory: "512Mi"
+ cpu: "250m"
\ No newline at end of file
diff --git a/k8s/docsgpt-secrets.yaml b/k8s/docsgpt-secrets.yaml
new file mode 100644
index 00000000..45a00973
--- /dev/null
+++ b/k8s/docsgpt-secrets.yaml
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Secret
+metadata:
+ name: docsgpt-secrets
+type: Opaque
+data:
+ LLM_NAME: ZG9jc2dwdA==
+ INTERNAL_KEY: aW50ZXJuYWw=
+ CELERY_BROKER_URL: cmVkaXM6Ly9yZWRpcy1zZXJ2aWNlOjYzNzkvMA==
+ CELERY_RESULT_BACKEND: cmVkaXM6Ly9yZWRpcy1zZXJ2aWNlOjYzNzkvMA==
+ QDRANT_URL: cmVkaXM6Ly9yZWRpcy1zZXJ2aWNlOjYzNzkvMA==
+ QDRANT_PORT: NjM3OQ==
+ MONGO_URI: bW9uZ29kYjovL21vbmdvZGItc2VydmljZToyNzAxNy9kb2NzZ3B0P3JldHJ5V3JpdGVzPXRydWUmdz1tYWpvcml0eQ==
+ mongo-user: bW9uZ28tdXNlcg==
+ mongo-password: bW9uZ28tcGFzc3dvcmQ=
\ No newline at end of file
diff --git a/k8s/services/docsgpt-service.yaml b/k8s/services/docsgpt-service.yaml
new file mode 100644
index 00000000..958d7c63
--- /dev/null
+++ b/k8s/services/docsgpt-service.yaml
@@ -0,0 +1,25 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: docsgpt-api-service
+spec:
+ selector:
+ app: docsgpt-api
+ ports:
+ - protocol: TCP
+ port: 80
+ targetPort: 7091
+ type: LoadBalancer
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: docsgpt-frontend-service
+spec:
+ selector:
+ app: docsgpt-frontend
+ ports:
+ - protocol: TCP
+ port: 80
+ targetPort: 5173
+ type: LoadBalancer
\ No newline at end of file
diff --git a/k8s/services/mongo-service.yaml b/k8s/services/mongo-service.yaml
new file mode 100644
index 00000000..0ea3db62
--- /dev/null
+++ b/k8s/services/mongo-service.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: mongodb-service
+spec:
+ selector:
+ app: mongodb
+ ports:
+ - protocol: TCP
+ port: 27017
+ targetPort: 27017
+ type: ClusterIP
\ No newline at end of file
diff --git a/k8s/services/qdrant-service.yaml b/k8s/services/qdrant-service.yaml
new file mode 100644
index 00000000..7ab395e8
--- /dev/null
+++ b/k8s/services/qdrant-service.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: qdrant
+spec:
+ selector:
+ app: qdrant
+ ports:
+ - protocol: TCP
+ port: 6333
+ targetPort: 6333
+ type: ClusterIP
\ No newline at end of file
diff --git a/k8s/services/redis-service.yaml b/k8s/services/redis-service.yaml
new file mode 100644
index 00000000..5d7dbf99
--- /dev/null
+++ b/k8s/services/redis-service.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: redis-service
+spec:
+ selector:
+ app: redis
+ ports:
+ - protocol: TCP
+ port: 6379
+ targetPort: 6379
+ type: ClusterIP
\ No newline at end of file
From 598a50a133dd2496781fde7882d18672cf4ac8d2 Mon Sep 17 00:00:00 2001
From: Alex
Date: Fri, 24 May 2024 14:40:28 +0100
Subject: [PATCH 2/2] feat: Add Kubernetes deployment instructions for DocsGPT
---
docs/pages/Deploying/Kubernetes-Deploying.md | 108 +++++++++++++++++++
docs/pages/Deploying/_meta.json | 4 +
k8s/deployments/docsgpt-deploy.yaml | 4 +-
k8s/docsgpt-secrets.yaml | 1 +
4 files changed, 115 insertions(+), 2 deletions(-)
create mode 100644 docs/pages/Deploying/Kubernetes-Deploying.md
diff --git a/docs/pages/Deploying/Kubernetes-Deploying.md b/docs/pages/Deploying/Kubernetes-Deploying.md
new file mode 100644
index 00000000..d7607bff
--- /dev/null
+++ b/docs/pages/Deploying/Kubernetes-Deploying.md
@@ -0,0 +1,108 @@
+# Self-hosting DocsGPT on Kubernetes
+
+This guide will walk you through deploying DocsGPT on Kubernetes.
+
+## Prerequisites
+
+Ensure you have the following installed before proceeding:
+
+- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
+- Access to a Kubernetes cluster
+
+## Folder Structure
+
+The `k8s` folder contains the necessary deployment and service configuration files:
+
+- `deployments/`
+- `services/`
+- `docsgpt-secrets.yaml`
+
+## Deployment Instructions
+
+1. **Clone the Repository**
+
+ ```sh
+ git clone https://github.com/arc53/DocsGPT.git
+ cd docsgpt/k8s
+ ```
+
+2. **Configure Secrets (optional)**
+
+ Ensure that you have all the necessary secrets in `docsgpt-secrets.yaml`. Update it with your secrets before applying if you want. By default we will use qdrant as a vectorstore and public docsgpt llm as llm for inference.
+
+3. **Apply Kubernetes Deployments**
+
+ Deploy your DocsGPT resources using the following commands:
+
+ ```sh
+ kubectl apply -f deployments/
+ ```
+
+4. **Apply Kubernetes Services**
+
+ Set up your services using the following commands:
+
+ ```sh
+ kubectl apply -f services/
+ ```
+
+5. **Apply Secrets**
+
+ Apply the secret configurations:
+
+ ```sh
+ kubectl apply -f docsgpt-secrets.yaml
+ ```
+
+6. **Substitute API URL**
+
+ After deploying the services, you need to update the environment variable `VITE_API_HOST` in your deployment file `deployments/docsgpt-deploy.yaml` with the actual endpoint URL created by your `docsgpt-api-service`.
+
+ You can get the value of the `docsgpt-api-service` by running:
+
+ ```sh
+ kubectl get services/docsgpt-api-service | awk 'NR>1 {print $4}'
+ ```
+
+ Update the `` field with your API endpoint URL by running this command and pasting endpoint from previous command:
+
+ ```sh
+ read -p "Enter the API endpoint: " api_endpoint && sed -i "s||$api_endpoint|g" deployments/docsgpt-deploy.yaml
+ ```
+
+7. **Rerun Deployment**
+
+ After making the changes, reapply the deployment configuration to update the environment variables:
+
+ ```sh
+ kubectl apply -f deployments/
+ ```
+
+## Verifying the Deployment
+
+To verify if everything is set up correctly, you can run the following:
+
+```sh
+kubectl get pods
+kubectl get services
+```
+
+Ensure that the pods are running and the services are available.
+
+## Accessing DocsGPT
+
+To access DocsGPT, you need to find the external IP address of the frontend service. You can do this by running:
+
+```sh
+kubectl get services/docsgpt-frontend-service | awk 'NR>1 {print "http://" $4}'
+```
+
+## Troubleshooting
+
+If you encounter any issues, you can check the logs of the pods for more details:
+
+```sh
+kubectl logs
+```
+
+Replace `` with the actual name of your DocsGPT pod.
\ No newline at end of file
diff --git a/docs/pages/Deploying/_meta.json b/docs/pages/Deploying/_meta.json
index 6d523a6d..2aec988e 100644
--- a/docs/pages/Deploying/_meta.json
+++ b/docs/pages/Deploying/_meta.json
@@ -10,5 +10,9 @@
"Railway-Deploying": {
"title": "🚂Deploying on Railway",
"href": "/Deploying/Railway-Deploying"
+ },
+ "Kubernetes-Deploying": {
+ "title": "🚀Deploying on Kubernetes",
+ "href": "/Deploying/Kubernetes-Deploying"
}
}
diff --git a/k8s/deployments/docsgpt-deploy.yaml b/k8s/deployments/docsgpt-deploy.yaml
index 1d0b86a3..815ff47f 100644
--- a/k8s/deployments/docsgpt-deploy.yaml
+++ b/k8s/deployments/docsgpt-deploy.yaml
@@ -63,7 +63,7 @@ spec:
name: docsgpt-secrets
env:
- name: API_URL
- value: "BACKEND-URL"
+ value: "http://"
---
apiVersion: apps/v1
kind: Deployment
@@ -93,6 +93,6 @@ spec:
cpu: "100m"
env:
- name: VITE_API_HOST
- value: "BACKEND-URL"
+ value: "http://"
- name: VITE_API_STREAMING
value: "true"
\ No newline at end of file
diff --git a/k8s/docsgpt-secrets.yaml b/k8s/docsgpt-secrets.yaml
index 45a00973..783b9b01 100644
--- a/k8s/docsgpt-secrets.yaml
+++ b/k8s/docsgpt-secrets.yaml
@@ -11,5 +11,6 @@ data:
QDRANT_URL: cmVkaXM6Ly9yZWRpcy1zZXJ2aWNlOjYzNzkvMA==
QDRANT_PORT: NjM3OQ==
MONGO_URI: bW9uZ29kYjovL21vbmdvZGItc2VydmljZToyNzAxNy9kb2NzZ3B0P3JldHJ5V3JpdGVzPXRydWUmdz1tYWpvcml0eQ==
+ VECTOR_STORE: cWRyYW50
mongo-user: bW9uZ28tdXNlcg==
mongo-password: bW9uZ28tcGFzc3dvcmQ=
\ No newline at end of file