diff --git a/docs/pages/Deploying/Kubernetes-Deploying.md b/docs/pages/Deploying/Kubernetes-Deploying.md new file mode 100644 index 00000000..b91ec343 --- /dev/null +++ b/docs/pages/Deploying/Kubernetes-Deploying.md @@ -0,0 +1,100 @@ +# 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`. + + ```sh + kubectl get services/docsgpt-api-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}' | xargs -I {} sed -i "s||{}|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 new file mode 100644 index 00000000..815ff47f --- /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: "http://" +--- +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: "http://" + - 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