From b07f52b335b6208590443f12e70e485b8399ae43 Mon Sep 17 00:00:00 2001 From: earayu Date: Wed, 14 May 2025 11:00:40 +0800 Subject: [PATCH 01/14] feat: add database helm --- deploy/kubeblocks-databases/Chart.yaml | 6 + deploy/kubeblocks-databases/NOTES.txt | 21 +++ deploy/kubeblocks-databases/README.md | 165 ++++++++++++++++++ .../templates/_helpers.tpl | 0 .../templates/elasticsearch-cluster.yaml | 31 ++++ .../templates/mongodb-cluster.yaml | 27 +++ .../templates/postgresql-cluster.yaml | 35 ++++ .../templates/qdrant-cluster.yaml | 27 +++ .../templates/redis-cluster.yaml | 36 ++++ deploy/kubeblocks-databases/values.yaml | 86 +++++++++ 10 files changed, 434 insertions(+) create mode 100644 deploy/kubeblocks-databases/Chart.yaml create mode 100644 deploy/kubeblocks-databases/NOTES.txt create mode 100644 deploy/kubeblocks-databases/README.md create mode 100644 deploy/kubeblocks-databases/templates/_helpers.tpl create mode 100644 deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml create mode 100644 deploy/kubeblocks-databases/templates/mongodb-cluster.yaml create mode 100644 deploy/kubeblocks-databases/templates/postgresql-cluster.yaml create mode 100644 deploy/kubeblocks-databases/templates/qdrant-cluster.yaml create mode 100644 deploy/kubeblocks-databases/templates/redis-cluster.yaml create mode 100644 deploy/kubeblocks-databases/values.yaml diff --git a/deploy/kubeblocks-databases/Chart.yaml b/deploy/kubeblocks-databases/Chart.yaml new file mode 100644 index 00000000..7768906a --- /dev/null +++ b/deploy/kubeblocks-databases/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: kubeblocks-databases +description: A Helm chart to deploy PostgreSQL, Redis, Elasticsearch, and Qdrant clusters using KubeBlocks. +type: application +version: 0.1.0 +appVersion: "1.0" # Or the version of KubeBlocks you are targeting diff --git a/deploy/kubeblocks-databases/NOTES.txt b/deploy/kubeblocks-databases/NOTES.txt new file mode 100644 index 00000000..351e6ca4 --- /dev/null +++ b/deploy/kubeblocks-databases/NOTES.txt @@ -0,0 +1,21 @@ +This Helm chart has deployed KubeBlocks database clusters as configured in your values.yaml. + +Enabled clusters: +{{- if .Values.postgresql.enabled }} + - PostgreSQL: {{ .Values.postgresql.name }} in namespace {{ .Values.global.namespace }} +{{- end }} +{{- if .Values.redis.enabled }} + - Redis: {{ .Values.redis.name }} in namespace {{ .Values.global.namespace }} +{{- end }} +{{- if .Values.elasticsearch.enabled }} + - Elasticsearch: {{ .Values.elasticsearch.name }} in namespace {{ .Values.global.namespace }} +{{- end }} +{{- if .Values.qdrant.enabled }} + - Qdrant: {{ .Values.qdrant.name }} in namespace {{ .Values.global.namespace }} +{{- end }} + +You can check the status of your clusters using kubectl: + kubectl get clusters -n {{ .Values.global.namespace }} + kubectl get pods -n {{ .Values.global.namespace }} + +For KubeBlocks specific commands, you might use the kbcli tool if installed. diff --git a/deploy/kubeblocks-databases/README.md b/deploy/kubeblocks-databases/README.md new file mode 100644 index 00000000..54b69b7d --- /dev/null +++ b/deploy/kubeblocks-databases/README.md @@ -0,0 +1,165 @@ +# KubeBlocks Databases Helm Chart + +This Helm chart deploys and manages multiple database clusters (PostgreSQL, Redis, Elasticsearch, Qdrant) using [KubeBlocks](https://kubeblocks.io/). + +## Prerequisites + +* Kubernetes cluster (version compatible with KubeBlocks) +* [Helm](https://helm.sh/docs/intro/install/) (version 3+) installed. +* [KubeBlocks](https://kubeblocks.io/docs/preview/user_docs/installation) installed in your Kubernetes cluster. +* `kubectl` configured to interact with your cluster. + +```bash +kubectl create namespace kb-system +kbcli kubeblocks install --version=1.0.0-beta.47 --namespace kb-system +``` + + +## Installation + +```bash +helm repo remove kubeblocks +helm repo add kubeblocks https://apecloud.github.io/helm-charts +helm repo update + +helm upgrade --install kb-addon-elasticsearch kubeblocks/elasticsearch --namespace kb-system --version 1.0.0-alpha.0 +helm upgrade --install kb-addon-qdrant kubeblocks/qdrant --namespace kb-system --version 1.0.0-alpha.0 +helm upgrade --install kb-addon-postgresql kubeblocks/postgresql --namespace kb-system --version 1.0.0-alpha.0 +helm upgrade --install kb-addon-redis kubeblocks/redis --namespace kb-system --version 1.0.0-alpha.0 +``` + +```bash +kubectl create namespace demo +kubectl create secret generic postgresql-secret \ + --namespace=demo \ + --from-literal=username=postgres \ + --from-literal=password=postgres +kubectl create secret generic redis-secret \ + --namespace=demo \ + --from-literal=username=default \ + --from-literal=password=password +helm install kb-databases ./kubeblocks-databases -n demo --create-namespace \ +--set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo +``` + +generate template: +```bash +helm template kb-databases ./kubeblocks-databases -n demo --create-namespace \ +--set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo \ +> rendered.yaml +``` + +## Verification + +After installation, you can check the status of the deployed KubeBlocks clusters: + +```bash +kubectl get clusters -n demo +kubectl get pods -n demo +``` + + +You should see the `Cluster` resources for the enabled databases and their corresponding pods. The `NOTES.txt` output from Helm will also provide some of this information. + +```bash +kubectl get clusters -n demo +NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE +es-cluster Delete Running 121m +pg-cluster postgresql Delete Creating 121m +qdrant-cluster qdrant Delete Running 121m +redis-standalone redis Delete Running 121m + +kubectl get pods -n demo +NAME READY STATUS RESTARTS AGE +es-cluster-mdit-0 3/3 Running 0 110m +pg-cluster-postgresql-0 5/5 Running 0 121m +qdrant-cluster-qdrant-0 2/2 Running 0 117m +redis-standalone-redis-0 3/3 Running 0 121m +``` + +## Connect + +port-forward: +```bash +echo "Starting Elasticsearch port-forward..." +kubectl port-forward -n demo service/es-cluster-mdit-http 9200:9200 & +ES_PID=$! +echo "Elasticsearch port-forward process ID: $ES_PID" +echo "Starting Qdrant port-forward..." +kubectl port-forward -n demo service/qdrant-cluster-qdrant-qdrant 6333:6333 & +QDRANT_PID=$! +echo "Qdrant port-forward process ID: $QDRANT_PID" +echo "Starting PostgreSQL port-forward..." +kubectl port-forward -n demo service/pg-cluster-postgresql-postgresql 5432:5432 & +PG_PID=$! +echo "PostgreSQL port-forward process ID: $PG_PID" +echo "Starting Redis port-forward..." +kubectl port-forward -n demo service/redis-standalone-redis-redis 6379:6379 & +REDIS_PID=$! +echo "Redis port-forward process ID: $REDIS_PID" +echo "All port-forwards have been started" +echo "Press Ctrl+C to stop all port-forwards" +# Capture Ctrl+C signal and clean up all processes +trap "kill $ES_PID $QDRANT_PID $PG_PID $REDIS_PID; echo 'All port-forwards stopped'; exit" INT +# Wait for any child process to finish +wait +``` + +## Uninstallation + +To uninstall the deployed database clusters: + +```bash +helm uninstall kb-databases -n demo +``` +This will remove all Kubernetes resources associated with this Helm release, including the KubeBlocks `Cluster` objects. Depending on the `terminationPolicy` and KubeBlocks behavior, PVCs might also be deleted. + + +## Configuration + +The primary way to configure the deployments is through the `values.yaml` file. + +### Global Settings + +These settings apply to all database clusters deployed by this chart: + +```yaml +global: + namespace: "demo" + terminationPolicy: "Delete" # Options: DoNotTerminate, Delete, WipeOut +``` + +### Per-Database Settings + +Each database (PostgreSQL, Redis, Elasticsearch, Qdrant) has its own configuration block. Here's an example for PostgreSQL: + +```yaml +postgresql: + enabled: true # Set to true to deploy this database, false to skip + name: "pg-cluster" # Name of the KubeBlocks Cluster resource + serviceVersion: "14.7.2" # Database engine version + disableExporter: false # true to disable metrics exporter, false to enable + replicas: 2 # Number of replicas for the main component + resources: # CPU and Memory requests/limits + limits: + cpu: "0.5" + memory: "0.5Gi" + requests: + cpu: "0.5" + memory: "0.5Gi" + storage: "20Gi" # Storage size for the data volume (e.g., PVC) +``` + +Refer to `values.yaml` for the full set of configurable options for each database. + +**Key configurable parameters for each database:** + +* `enabled`: (boolean) Deploy this database cluster. +* `name`: (string) Name for the KubeBlocks `Cluster` resource. +* `serviceVersion`: (string) Specific version of the database engine. +* `disableExporter`: (boolean) Enable/disable the metrics exporter. (Note: For Elasticsearch, this might be handled differently by its `componentDef`). +* `replicas`: (integer) Number of replicas for the primary database component. +* `resources`: (object) Standard Kubernetes resource requests and limits. +* `storage`: (string) Storage capacity for persistent volumes (e.g., "10Gi", "100Gi"). +* `topology`: (string, for Redis) e.g., "standalone", "replication". +* `componentDef`: (string, for Elasticsearch) e.g., "elasticsearch-8". diff --git a/deploy/kubeblocks-databases/templates/_helpers.tpl b/deploy/kubeblocks-databases/templates/_helpers.tpl new file mode 100644 index 00000000..e69de29b diff --git a/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml b/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml new file mode 100644 index 00000000..c0b2a92e --- /dev/null +++ b/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml @@ -0,0 +1,31 @@ +{{- if .Values.elasticsearch.enabled }} +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: {{ .Values.elasticsearch.name }} + namespace: {{ .Values.global.namespace }} +spec: + terminationPolicy: {{ .Values.global.terminationPolicy }} + # Elasticsearch example provided doesn't specify clusterDef or topology at the spec level + # It's often defined by the componentDef within componentSpecs for KubeBlocks' ES + componentSpecs: + - name: mdit # Component name from your example, can be made configurable if needed + componentDef: {{ .Values.elasticsearch.componentDef }} + serviceVersion: "{{ .Values.elasticsearch.serviceVersion }}" + replicas: {{ .Values.elasticsearch.replicas }} + configs: # Hardcoding single-node config as per your example and simplicity request + - name: es-cm + variables: + mode: "single-node" + resources: + {{- toYaml .Values.elasticsearch.resources | nindent 8 }} + volumeClaimTemplates: + - name: data + spec: + storageClassName: "" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.elasticsearch.storage }} +{{- end }} diff --git a/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml b/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml new file mode 100644 index 00000000..153dfb9d --- /dev/null +++ b/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml @@ -0,0 +1,27 @@ +{{- if .Values.mongodb.enabled }} +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: {{ .Values.mongodb.name }} + namespace: {{ .Values.global.namespace }} +spec: + terminationPolicy: {{ .Values.global.terminationPolicy }} + clusterDef: mongodb + topology: {{ .Values.mongodb.topology }} + componentSpecs: + - name: mongodb + serviceVersion: "{{ .Values.mongodb.serviceVersion }}" + disableExporter: {{ .Values.mongodb.disableExporter }} + replicas: {{ .Values.mongodb.replicas }} + resources: + {{- toYaml .Values.mongodb.resources | nindent 8 }} + volumeClaimTemplates: + - name: data + spec: + storageClassName: "{{ .Values.mongodb.storageClassName }}" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.mongodb.storage }} +{{- end }} diff --git a/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml b/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml new file mode 100644 index 00000000..fbb1db7b --- /dev/null +++ b/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml @@ -0,0 +1,35 @@ +{{- if .Values.postgresql.enabled }} +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: {{ .Values.postgresql.name }} + namespace: {{ .Values.global.namespace }} +spec: + terminationPolicy: {{ .Values.global.terminationPolicy }} + clusterDef: postgresql + topology: replication # As per your example + componentSpecs: + - name: postgresql # Default component name for PostgreSQL + serviceVersion: "{{ .Values.postgresql.serviceVersion }}" + disableExporter: {{ .Values.postgresql.disableExporter }} + labels: + # Specific label for Patroni scope + apps.kubeblocks.postgres.patroni/scope: {{ .Values.postgresql.name }}-postgresql + replicas: {{ .Values.postgresql.replicas }} + systemAccounts: + - name: postgres + secretRef: + name: {{ .Values.postgresql.customSecretName }} + namespace: {{ .Values.postgresql.customSecretNamespace }} + resources: + {{- toYaml .Values.postgresql.resources | nindent 8 }} + volumeClaimTemplates: + - name: data + spec: + storageClassName: "" # Or make this configurable if needed + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.postgresql.storage }} +{{- end }} diff --git a/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml b/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml new file mode 100644 index 00000000..13ef0fc5 --- /dev/null +++ b/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml @@ -0,0 +1,27 @@ +{{- if .Values.qdrant.enabled }} +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: {{ .Values.qdrant.name }} + namespace: {{ .Values.global.namespace }} +spec: + terminationPolicy: {{ .Values.global.terminationPolicy }} + clusterDef: qdrant + topology: cluster # As per your example + componentSpecs: + - name: qdrant # Default component name for Qdrant + serviceVersion: "{{ .Values.qdrant.serviceVersion }}" + disableExporter: {{ .Values.qdrant.disableExporter }} + replicas: {{ .Values.qdrant.replicas }} + resources: + {{- toYaml .Values.qdrant.resources | nindent 8 }} + volumeClaimTemplates: + - name: data + spec: + storageClassName: "" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.qdrant.storage }} +{{- end }} diff --git a/deploy/kubeblocks-databases/templates/redis-cluster.yaml b/deploy/kubeblocks-databases/templates/redis-cluster.yaml new file mode 100644 index 00000000..a83ca194 --- /dev/null +++ b/deploy/kubeblocks-databases/templates/redis-cluster.yaml @@ -0,0 +1,36 @@ +{{- if .Values.redis.enabled }} +apiVersion: apps.kubeblocks.io/v1 +kind: Cluster +metadata: + name: {{ .Values.redis.name }} + namespace: {{ .Values.global.namespace }} +spec: + terminationPolicy: {{ .Values.global.terminationPolicy }} + clusterDef: redis + topology: {{ .Values.redis.topology }} # Use topology from values + componentSpecs: + - name: redis # Main Redis component + {{- if .Values.redis.serviceVersion }} # serviceVersion is optional for some clusterDefs + serviceVersion: "{{ .Values.redis.serviceVersion }}" + {{- end }} + {{- if (not ( eq .Values.redis.disableExporter nil )) }} # disableExporter is also optional + disableExporter: {{ .Values.redis.disableExporter }} + {{- end }} + replicas: {{ .Values.redis.replicas }} + systemAccounts: + - name: default + secretRef: + name: {{ .Values.redis.customSecretName }} + namespace: {{ .Values.redis.customSecretNamespace }} + resources: + {{- toYaml .Values.redis.resources | nindent 8 }} + volumeClaimTemplates: + - name: data + spec: + storageClassName: "" # Or make this configurable + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.redis.storage }} +{{- end }} diff --git a/deploy/kubeblocks-databases/values.yaml b/deploy/kubeblocks-databases/values.yaml new file mode 100644 index 00000000..254ab1b6 --- /dev/null +++ b/deploy/kubeblocks-databases/values.yaml @@ -0,0 +1,86 @@ +# Global settings applicable to all database clusters +global: + namespace: "demo" # The namespace where all clusters will be deployed + terminationPolicy: "Delete" # Common termination policy + +postgresql: + enabled: true + name: "pg-cluster" # Name for the PostgreSQL cluster + serviceVersion: "14.7.2" + disableExporter: false # Corresponds to Kubeblocks disableExporter + customSecretName: + customSecretNamespace: + replicas: 1 + resources: + limits: + cpu: "1" + memory: "1Gi" + requests: + cpu: "1" + memory: "1Gi" + storage: "5Gi" + +redis: + enabled: true + name: "redis-standalone" # Name for the Redis cluster + topology: "standalone" # Explicitly set topology + serviceVersion: "7.2.4" # Keep or update as needed + disableExporter: false # Keep or update as needed + customSecretName: + customSecretNamespace: + replicas: 1 # Standalone typically means 1 replica + resources: + limits: + cpu: "1" + memory: "1Gi" + requests: + cpu: "1" + memory: "1Gi" + storage: "5Gi" + +elasticsearch: + enabled: true + name: "es-cluster" # Name for the Elasticsearch cluster + componentDef: "elasticsearch-8" # Example: "elasticsearch-8" + serviceVersion: "8.8.2" + replicas: 1 # For the 'mdit' component (or whatever the main ES component is named) + resources: + limits: + cpu: "1" + memory: "1Gi" + requests: + cpu: "1" + memory: "1Gi" + storage: "5Gi" + +qdrant: + enabled: true + name: "qdrant-cluster" # Name for the Qdrant cluster + serviceVersion: "1.10.0" + disableExporter: false + replicas: 1 + resources: + limits: + cpu: "1" + memory: "1Gi" + requests: + cpu: "1" + memory: "1Gi" + storage: "5Gi" + +mongodb: + enabled: false + name: "mongo-cluster" + serviceVersion: "6.0.16" + topology: replicaset + disableExporter: false + replicas: 3 + resources: + limits: + cpu: "0.5" + memory: "0.5Gi" + requests: + cpu: "0.5" + memory: "0.5Gi" + storageClassName: "" + storage: 20Gi From 573920d5bdc22609147fff5e34b1e720da5315f0 Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 18:11:25 +0800 Subject: [PATCH 02/14] feat: add helm chart --- deploy/kubeblocks-databases/Chart.yaml | 6 - deploy/kubeblocks-databases/NOTES.txt | 21 -- deploy/kubeblocks-databases/README.md | 165 --------------- .../templates/_helpers.tpl | 0 .../templates/elasticsearch-cluster.yaml | 31 --- .../templates/mongodb-cluster.yaml | 27 --- .../templates/postgresql-cluster.yaml | 35 ---- .../templates/qdrant-cluster.yaml | 27 --- .../templates/redis-cluster.yaml | 36 ---- deploy/kubeblocks-databases/values.yaml | 86 -------- k8s-deploy/README.md | 191 ++++++++++++++++++ k8s-deploy/databases/00-config.sh | 21 ++ k8s-deploy/databases/01-prepare.sh | 33 +++ k8s-deploy/databases/02-install-database.sh | 24 +++ k8s-deploy/databases/03-uninstall-database.sh | 20 ++ k8s-deploy/databases/04-cleanup.sh | 26 +++ k8s-deploy/databases/README.md | 170 ++++++++++++++++ .../databases/elasticsearch/values.yaml | 36 ++++ k8s-deploy/databases/install-kubeblocks.sh | 52 +++++ k8s-deploy/databases/mongodb/values.yaml | 34 ++++ k8s-deploy/databases/neo4j/values.yaml | 46 +++++ k8s-deploy/databases/postgresql/values.yaml | 33 +++ k8s-deploy/databases/qdrant/values.yaml | 31 +++ k8s-deploy/databases/redis/values.yaml | 34 ++++ k8s-deploy/databases/scripts/common.sh | 43 ++++ k8s-deploy/databases/uninstall-kubeblocks.sh | 52 +++++ k8s-deploy/install_lightrag.sh | 105 ++++++++++ k8s-deploy/install_lightrag_dev.sh | 57 ++++++ k8s-deploy/lightrag/.helmignore | 23 +++ k8s-deploy/lightrag/Chart.yaml | 10 + k8s-deploy/lightrag/templates/NOTES.txt | 38 ++++ k8s-deploy/lightrag/templates/_helpers.tpl | 42 ++++ k8s-deploy/lightrag/templates/deployment.yaml | 53 +++++ k8s-deploy/lightrag/templates/pvc.yaml | 28 +++ k8s-deploy/lightrag/templates/secret.yaml | 10 + k8s-deploy/lightrag/templates/service.yaml | 15 ++ k8s-deploy/lightrag/values.yaml | 53 +++++ k8s-deploy/uninstall_lightrag.sh | 4 + k8s-deploy/uninstall_lightrag_dev.sh | 4 + 39 files changed, 1288 insertions(+), 434 deletions(-) delete mode 100644 deploy/kubeblocks-databases/Chart.yaml delete mode 100644 deploy/kubeblocks-databases/NOTES.txt delete mode 100644 deploy/kubeblocks-databases/README.md delete mode 100644 deploy/kubeblocks-databases/templates/_helpers.tpl delete mode 100644 deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml delete mode 100644 deploy/kubeblocks-databases/templates/mongodb-cluster.yaml delete mode 100644 deploy/kubeblocks-databases/templates/postgresql-cluster.yaml delete mode 100644 deploy/kubeblocks-databases/templates/qdrant-cluster.yaml delete mode 100644 deploy/kubeblocks-databases/templates/redis-cluster.yaml delete mode 100644 deploy/kubeblocks-databases/values.yaml create mode 100644 k8s-deploy/README.md create mode 100755 k8s-deploy/databases/00-config.sh create mode 100755 k8s-deploy/databases/01-prepare.sh create mode 100755 k8s-deploy/databases/02-install-database.sh create mode 100755 k8s-deploy/databases/03-uninstall-database.sh create mode 100755 k8s-deploy/databases/04-cleanup.sh create mode 100644 k8s-deploy/databases/README.md create mode 100644 k8s-deploy/databases/elasticsearch/values.yaml create mode 100644 k8s-deploy/databases/install-kubeblocks.sh create mode 100644 k8s-deploy/databases/mongodb/values.yaml create mode 100644 k8s-deploy/databases/neo4j/values.yaml create mode 100644 k8s-deploy/databases/postgresql/values.yaml create mode 100644 k8s-deploy/databases/qdrant/values.yaml create mode 100644 k8s-deploy/databases/redis/values.yaml create mode 100644 k8s-deploy/databases/scripts/common.sh create mode 100644 k8s-deploy/databases/uninstall-kubeblocks.sh create mode 100755 k8s-deploy/install_lightrag.sh create mode 100755 k8s-deploy/install_lightrag_dev.sh create mode 100644 k8s-deploy/lightrag/.helmignore create mode 100644 k8s-deploy/lightrag/Chart.yaml create mode 100644 k8s-deploy/lightrag/templates/NOTES.txt create mode 100644 k8s-deploy/lightrag/templates/_helpers.tpl create mode 100644 k8s-deploy/lightrag/templates/deployment.yaml create mode 100644 k8s-deploy/lightrag/templates/pvc.yaml create mode 100644 k8s-deploy/lightrag/templates/secret.yaml create mode 100644 k8s-deploy/lightrag/templates/service.yaml create mode 100644 k8s-deploy/lightrag/values.yaml create mode 100644 k8s-deploy/uninstall_lightrag.sh create mode 100644 k8s-deploy/uninstall_lightrag_dev.sh diff --git a/deploy/kubeblocks-databases/Chart.yaml b/deploy/kubeblocks-databases/Chart.yaml deleted file mode 100644 index 7768906a..00000000 --- a/deploy/kubeblocks-databases/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v2 -name: kubeblocks-databases -description: A Helm chart to deploy PostgreSQL, Redis, Elasticsearch, and Qdrant clusters using KubeBlocks. -type: application -version: 0.1.0 -appVersion: "1.0" # Or the version of KubeBlocks you are targeting diff --git a/deploy/kubeblocks-databases/NOTES.txt b/deploy/kubeblocks-databases/NOTES.txt deleted file mode 100644 index 351e6ca4..00000000 --- a/deploy/kubeblocks-databases/NOTES.txt +++ /dev/null @@ -1,21 +0,0 @@ -This Helm chart has deployed KubeBlocks database clusters as configured in your values.yaml. - -Enabled clusters: -{{- if .Values.postgresql.enabled }} - - PostgreSQL: {{ .Values.postgresql.name }} in namespace {{ .Values.global.namespace }} -{{- end }} -{{- if .Values.redis.enabled }} - - Redis: {{ .Values.redis.name }} in namespace {{ .Values.global.namespace }} -{{- end }} -{{- if .Values.elasticsearch.enabled }} - - Elasticsearch: {{ .Values.elasticsearch.name }} in namespace {{ .Values.global.namespace }} -{{- end }} -{{- if .Values.qdrant.enabled }} - - Qdrant: {{ .Values.qdrant.name }} in namespace {{ .Values.global.namespace }} -{{- end }} - -You can check the status of your clusters using kubectl: - kubectl get clusters -n {{ .Values.global.namespace }} - kubectl get pods -n {{ .Values.global.namespace }} - -For KubeBlocks specific commands, you might use the kbcli tool if installed. diff --git a/deploy/kubeblocks-databases/README.md b/deploy/kubeblocks-databases/README.md deleted file mode 100644 index 54b69b7d..00000000 --- a/deploy/kubeblocks-databases/README.md +++ /dev/null @@ -1,165 +0,0 @@ -# KubeBlocks Databases Helm Chart - -This Helm chart deploys and manages multiple database clusters (PostgreSQL, Redis, Elasticsearch, Qdrant) using [KubeBlocks](https://kubeblocks.io/). - -## Prerequisites - -* Kubernetes cluster (version compatible with KubeBlocks) -* [Helm](https://helm.sh/docs/intro/install/) (version 3+) installed. -* [KubeBlocks](https://kubeblocks.io/docs/preview/user_docs/installation) installed in your Kubernetes cluster. -* `kubectl` configured to interact with your cluster. - -```bash -kubectl create namespace kb-system -kbcli kubeblocks install --version=1.0.0-beta.47 --namespace kb-system -``` - - -## Installation - -```bash -helm repo remove kubeblocks -helm repo add kubeblocks https://apecloud.github.io/helm-charts -helm repo update - -helm upgrade --install kb-addon-elasticsearch kubeblocks/elasticsearch --namespace kb-system --version 1.0.0-alpha.0 -helm upgrade --install kb-addon-qdrant kubeblocks/qdrant --namespace kb-system --version 1.0.0-alpha.0 -helm upgrade --install kb-addon-postgresql kubeblocks/postgresql --namespace kb-system --version 1.0.0-alpha.0 -helm upgrade --install kb-addon-redis kubeblocks/redis --namespace kb-system --version 1.0.0-alpha.0 -``` - -```bash -kubectl create namespace demo -kubectl create secret generic postgresql-secret \ - --namespace=demo \ - --from-literal=username=postgres \ - --from-literal=password=postgres -kubectl create secret generic redis-secret \ - --namespace=demo \ - --from-literal=username=default \ - --from-literal=password=password -helm install kb-databases ./kubeblocks-databases -n demo --create-namespace \ ---set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo -``` - -generate template: -```bash -helm template kb-databases ./kubeblocks-databases -n demo --create-namespace \ ---set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo \ -> rendered.yaml -``` - -## Verification - -After installation, you can check the status of the deployed KubeBlocks clusters: - -```bash -kubectl get clusters -n demo -kubectl get pods -n demo -``` - - -You should see the `Cluster` resources for the enabled databases and their corresponding pods. The `NOTES.txt` output from Helm will also provide some of this information. - -```bash -kubectl get clusters -n demo -NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE -es-cluster Delete Running 121m -pg-cluster postgresql Delete Creating 121m -qdrant-cluster qdrant Delete Running 121m -redis-standalone redis Delete Running 121m - -kubectl get pods -n demo -NAME READY STATUS RESTARTS AGE -es-cluster-mdit-0 3/3 Running 0 110m -pg-cluster-postgresql-0 5/5 Running 0 121m -qdrant-cluster-qdrant-0 2/2 Running 0 117m -redis-standalone-redis-0 3/3 Running 0 121m -``` - -## Connect - -port-forward: -```bash -echo "Starting Elasticsearch port-forward..." -kubectl port-forward -n demo service/es-cluster-mdit-http 9200:9200 & -ES_PID=$! -echo "Elasticsearch port-forward process ID: $ES_PID" -echo "Starting Qdrant port-forward..." -kubectl port-forward -n demo service/qdrant-cluster-qdrant-qdrant 6333:6333 & -QDRANT_PID=$! -echo "Qdrant port-forward process ID: $QDRANT_PID" -echo "Starting PostgreSQL port-forward..." -kubectl port-forward -n demo service/pg-cluster-postgresql-postgresql 5432:5432 & -PG_PID=$! -echo "PostgreSQL port-forward process ID: $PG_PID" -echo "Starting Redis port-forward..." -kubectl port-forward -n demo service/redis-standalone-redis-redis 6379:6379 & -REDIS_PID=$! -echo "Redis port-forward process ID: $REDIS_PID" -echo "All port-forwards have been started" -echo "Press Ctrl+C to stop all port-forwards" -# Capture Ctrl+C signal and clean up all processes -trap "kill $ES_PID $QDRANT_PID $PG_PID $REDIS_PID; echo 'All port-forwards stopped'; exit" INT -# Wait for any child process to finish -wait -``` - -## Uninstallation - -To uninstall the deployed database clusters: - -```bash -helm uninstall kb-databases -n demo -``` -This will remove all Kubernetes resources associated with this Helm release, including the KubeBlocks `Cluster` objects. Depending on the `terminationPolicy` and KubeBlocks behavior, PVCs might also be deleted. - - -## Configuration - -The primary way to configure the deployments is through the `values.yaml` file. - -### Global Settings - -These settings apply to all database clusters deployed by this chart: - -```yaml -global: - namespace: "demo" - terminationPolicy: "Delete" # Options: DoNotTerminate, Delete, WipeOut -``` - -### Per-Database Settings - -Each database (PostgreSQL, Redis, Elasticsearch, Qdrant) has its own configuration block. Here's an example for PostgreSQL: - -```yaml -postgresql: - enabled: true # Set to true to deploy this database, false to skip - name: "pg-cluster" # Name of the KubeBlocks Cluster resource - serviceVersion: "14.7.2" # Database engine version - disableExporter: false # true to disable metrics exporter, false to enable - replicas: 2 # Number of replicas for the main component - resources: # CPU and Memory requests/limits - limits: - cpu: "0.5" - memory: "0.5Gi" - requests: - cpu: "0.5" - memory: "0.5Gi" - storage: "20Gi" # Storage size for the data volume (e.g., PVC) -``` - -Refer to `values.yaml` for the full set of configurable options for each database. - -**Key configurable parameters for each database:** - -* `enabled`: (boolean) Deploy this database cluster. -* `name`: (string) Name for the KubeBlocks `Cluster` resource. -* `serviceVersion`: (string) Specific version of the database engine. -* `disableExporter`: (boolean) Enable/disable the metrics exporter. (Note: For Elasticsearch, this might be handled differently by its `componentDef`). -* `replicas`: (integer) Number of replicas for the primary database component. -* `resources`: (object) Standard Kubernetes resource requests and limits. -* `storage`: (string) Storage capacity for persistent volumes (e.g., "10Gi", "100Gi"). -* `topology`: (string, for Redis) e.g., "standalone", "replication". -* `componentDef`: (string, for Elasticsearch) e.g., "elasticsearch-8". diff --git a/deploy/kubeblocks-databases/templates/_helpers.tpl b/deploy/kubeblocks-databases/templates/_helpers.tpl deleted file mode 100644 index e69de29b..00000000 diff --git a/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml b/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml deleted file mode 100644 index c0b2a92e..00000000 --- a/deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml +++ /dev/null @@ -1,31 +0,0 @@ -{{- if .Values.elasticsearch.enabled }} -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ .Values.elasticsearch.name }} - namespace: {{ .Values.global.namespace }} -spec: - terminationPolicy: {{ .Values.global.terminationPolicy }} - # Elasticsearch example provided doesn't specify clusterDef or topology at the spec level - # It's often defined by the componentDef within componentSpecs for KubeBlocks' ES - componentSpecs: - - name: mdit # Component name from your example, can be made configurable if needed - componentDef: {{ .Values.elasticsearch.componentDef }} - serviceVersion: "{{ .Values.elasticsearch.serviceVersion }}" - replicas: {{ .Values.elasticsearch.replicas }} - configs: # Hardcoding single-node config as per your example and simplicity request - - name: es-cm - variables: - mode: "single-node" - resources: - {{- toYaml .Values.elasticsearch.resources | nindent 8 }} - volumeClaimTemplates: - - name: data - spec: - storageClassName: "" - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.elasticsearch.storage }} -{{- end }} diff --git a/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml b/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml deleted file mode 100644 index 153dfb9d..00000000 --- a/deploy/kubeblocks-databases/templates/mongodb-cluster.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.mongodb.enabled }} -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ .Values.mongodb.name }} - namespace: {{ .Values.global.namespace }} -spec: - terminationPolicy: {{ .Values.global.terminationPolicy }} - clusterDef: mongodb - topology: {{ .Values.mongodb.topology }} - componentSpecs: - - name: mongodb - serviceVersion: "{{ .Values.mongodb.serviceVersion }}" - disableExporter: {{ .Values.mongodb.disableExporter }} - replicas: {{ .Values.mongodb.replicas }} - resources: - {{- toYaml .Values.mongodb.resources | nindent 8 }} - volumeClaimTemplates: - - name: data - spec: - storageClassName: "{{ .Values.mongodb.storageClassName }}" - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.mongodb.storage }} -{{- end }} diff --git a/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml b/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml deleted file mode 100644 index fbb1db7b..00000000 --- a/deploy/kubeblocks-databases/templates/postgresql-cluster.yaml +++ /dev/null @@ -1,35 +0,0 @@ -{{- if .Values.postgresql.enabled }} -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ .Values.postgresql.name }} - namespace: {{ .Values.global.namespace }} -spec: - terminationPolicy: {{ .Values.global.terminationPolicy }} - clusterDef: postgresql - topology: replication # As per your example - componentSpecs: - - name: postgresql # Default component name for PostgreSQL - serviceVersion: "{{ .Values.postgresql.serviceVersion }}" - disableExporter: {{ .Values.postgresql.disableExporter }} - labels: - # Specific label for Patroni scope - apps.kubeblocks.postgres.patroni/scope: {{ .Values.postgresql.name }}-postgresql - replicas: {{ .Values.postgresql.replicas }} - systemAccounts: - - name: postgres - secretRef: - name: {{ .Values.postgresql.customSecretName }} - namespace: {{ .Values.postgresql.customSecretNamespace }} - resources: - {{- toYaml .Values.postgresql.resources | nindent 8 }} - volumeClaimTemplates: - - name: data - spec: - storageClassName: "" # Or make this configurable if needed - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.postgresql.storage }} -{{- end }} diff --git a/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml b/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml deleted file mode 100644 index 13ef0fc5..00000000 --- a/deploy/kubeblocks-databases/templates/qdrant-cluster.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.qdrant.enabled }} -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ .Values.qdrant.name }} - namespace: {{ .Values.global.namespace }} -spec: - terminationPolicy: {{ .Values.global.terminationPolicy }} - clusterDef: qdrant - topology: cluster # As per your example - componentSpecs: - - name: qdrant # Default component name for Qdrant - serviceVersion: "{{ .Values.qdrant.serviceVersion }}" - disableExporter: {{ .Values.qdrant.disableExporter }} - replicas: {{ .Values.qdrant.replicas }} - resources: - {{- toYaml .Values.qdrant.resources | nindent 8 }} - volumeClaimTemplates: - - name: data - spec: - storageClassName: "" - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.qdrant.storage }} -{{- end }} diff --git a/deploy/kubeblocks-databases/templates/redis-cluster.yaml b/deploy/kubeblocks-databases/templates/redis-cluster.yaml deleted file mode 100644 index a83ca194..00000000 --- a/deploy/kubeblocks-databases/templates/redis-cluster.yaml +++ /dev/null @@ -1,36 +0,0 @@ -{{- if .Values.redis.enabled }} -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ .Values.redis.name }} - namespace: {{ .Values.global.namespace }} -spec: - terminationPolicy: {{ .Values.global.terminationPolicy }} - clusterDef: redis - topology: {{ .Values.redis.topology }} # Use topology from values - componentSpecs: - - name: redis # Main Redis component - {{- if .Values.redis.serviceVersion }} # serviceVersion is optional for some clusterDefs - serviceVersion: "{{ .Values.redis.serviceVersion }}" - {{- end }} - {{- if (not ( eq .Values.redis.disableExporter nil )) }} # disableExporter is also optional - disableExporter: {{ .Values.redis.disableExporter }} - {{- end }} - replicas: {{ .Values.redis.replicas }} - systemAccounts: - - name: default - secretRef: - name: {{ .Values.redis.customSecretName }} - namespace: {{ .Values.redis.customSecretNamespace }} - resources: - {{- toYaml .Values.redis.resources | nindent 8 }} - volumeClaimTemplates: - - name: data - spec: - storageClassName: "" # Or make this configurable - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.redis.storage }} -{{- end }} diff --git a/deploy/kubeblocks-databases/values.yaml b/deploy/kubeblocks-databases/values.yaml deleted file mode 100644 index 254ab1b6..00000000 --- a/deploy/kubeblocks-databases/values.yaml +++ /dev/null @@ -1,86 +0,0 @@ -# Global settings applicable to all database clusters -global: - namespace: "demo" # The namespace where all clusters will be deployed - terminationPolicy: "Delete" # Common termination policy - -postgresql: - enabled: true - name: "pg-cluster" # Name for the PostgreSQL cluster - serviceVersion: "14.7.2" - disableExporter: false # Corresponds to Kubeblocks disableExporter - customSecretName: - customSecretNamespace: - replicas: 1 - resources: - limits: - cpu: "1" - memory: "1Gi" - requests: - cpu: "1" - memory: "1Gi" - storage: "5Gi" - -redis: - enabled: true - name: "redis-standalone" # Name for the Redis cluster - topology: "standalone" # Explicitly set topology - serviceVersion: "7.2.4" # Keep or update as needed - disableExporter: false # Keep or update as needed - customSecretName: - customSecretNamespace: - replicas: 1 # Standalone typically means 1 replica - resources: - limits: - cpu: "1" - memory: "1Gi" - requests: - cpu: "1" - memory: "1Gi" - storage: "5Gi" - -elasticsearch: - enabled: true - name: "es-cluster" # Name for the Elasticsearch cluster - componentDef: "elasticsearch-8" # Example: "elasticsearch-8" - serviceVersion: "8.8.2" - replicas: 1 # For the 'mdit' component (or whatever the main ES component is named) - resources: - limits: - cpu: "1" - memory: "1Gi" - requests: - cpu: "1" - memory: "1Gi" - storage: "5Gi" - -qdrant: - enabled: true - name: "qdrant-cluster" # Name for the Qdrant cluster - serviceVersion: "1.10.0" - disableExporter: false - replicas: 1 - resources: - limits: - cpu: "1" - memory: "1Gi" - requests: - cpu: "1" - memory: "1Gi" - storage: "5Gi" - -mongodb: - enabled: false - name: "mongo-cluster" - serviceVersion: "6.0.16" - topology: replicaset - disableExporter: false - replicas: 3 - resources: - limits: - cpu: "0.5" - memory: "0.5Gi" - requests: - cpu: "0.5" - memory: "0.5Gi" - storageClassName: "" - storage: 20Gi diff --git a/k8s-deploy/README.md b/k8s-deploy/README.md new file mode 100644 index 00000000..9a3d070a --- /dev/null +++ b/k8s-deploy/README.md @@ -0,0 +1,191 @@ +# LightRAG Helm Chart + +This is the Helm chart for LightRAG, used to deploy LightRAG services on a Kubernetes cluster. + +There are two recommended deployment methods for LightRAG: +1. **Lightweight Deployment**: Using built-in lightweight storage, suitable for testing and small-scale usage +2. **Full Deployment**: Using external databases (such as PostgreSQL and Neo4J), suitable for production environments and large-scale usage + +## Prerequisites + +Make sure the following tools are installed and configured: + +* **Kubernetes cluster** + * A running Kubernetes cluster is required. + * For local development or demos you can use [Minikube](https://minikube.sigs.k8s.io/docs/start/) (needs ≥ 2 CPUs, ≥ 4 GB RAM, and Docker/VM-driver support). + * Any standard cloud or on-premises Kubernetes cluster (EKS, GKE, AKS, etc.) also works. + +* **kubectl** + * The Kubernetes command-line interface. + * Follow the official guide: [Install and Set Up kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl). + +* **Helm** (v3.x+) + * Kubernetes package manager used by the scripts below. + * Install it via the official instructions: [Installing Helm](https://helm.sh/docs/intro/install/). + + +## Lightweight Deployment (No External Databases Required) + +Uses built-in lightweight storage components with no need to configure external databases: + +```bash +helm upgrade --install lightrag ./lightrag \ + --namespace rag \ + --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ + --set-string env.LIGHTRAG_VECTOR_STORAGE=NanoVectorDBStorage \ + --set-string env.LIGHTRAG_GRAPH_STORAGE=NetworkXStorage \ + --set-string env.LIGHTRAG_DOC_STATUS_STORAGE=JsonDocStatusStorage \ + --set-string env.LLM_BINDING=openai \ + --set-string env.LLM_MODEL=gpt-4o-mini \ + --set-string env.LLM_BINDING_HOST=$OPENAI_API_BASE \ + --set-string env.LLM_BINDING_API_KEY=$OPENAI_API_KEY \ + --set-string env.EMBEDDING_BINDING=openai \ + --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ + --set-string env.EMBEDDING_DIM=1536 \ + --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY +``` + +You can refer to: [install_lightrag_dev.sh](install_lightrag_dev.sh) + +You can use it directly like this: +```bash +export OPENAI_API_BASE= +export OPENAI_API_KEY= +bash ./install_lightrag_dev.sh +``` +Then you can Access the application +```bash + 1. Run this port-forward command in your terminal: + kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621 + + 2. While the command is running, open your browser and navigate to: + http://localhost:9621 +``` + +## Full Deployment (Using External Databases) + +### 1. Install Databases +> You can skip this step if you've already prepared databases. Detailed information can be found in: [README.md](databases%2FREADME.md). + +We recommend KubeBlocks for database deployment. KubeBlocks is a cloud-native database operator that makes it easy to run any database on Kubernetes at production scale. +FastGPT also use KubeBlocks for their database infrastructure. + +First, install KubeBlocks and KubeBlocks-Addons (skip if already installed): +```bash +bash ./databases/01-prepare.sh +``` + +Then install the required databases. By default, this will install PostgreSQL and Neo4J, but you can modify [00-config.sh](databases%2F00-config.sh) to select different databases based on your needs. KubeBlocks supports various databases including MongoDB, Qdrant, Redis, and more. +```bash +bash ./databases/02-install-database.sh +``` + +When the script completes, confirm that the clusters are up. It may take a few minutes for all the clusters to become ready, + especially if this is the first time running the script as Kubernetes needs to pull container images from registries. + You can monitor the progress using the following commands: +```bash +kubectl get clusters -n rag +NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE +neo4j-cluster Delete Running 39s +pg-cluster postgresql Delete Creating 42s +``` +You can see all the Database `Pods` created by KubeBlocks. + Initially, you might see pods in `ContainerCreating` or `Pending` status - this is normal while images are being pulled and containers are starting up. + Wait until all pods show `Running` status: +```bash +kubectl get po -n rag +NAME READY STATUS RESTARTS AGE +neo4j-cluster-neo4j-0 1/1 Running 0 58s +pg-cluster-postgresql-0 4/4 Running 0 59s +pg-cluster-postgresql-1 4/4 Running 0 59s +``` + +### 2. Install LightRAG + +LightRAG and its databases are deployed within the same Kubernetes cluster, making configuration straightforward. +When using KubeBlocks to provide PostgreSQL and Neo4J database services, the `install_lightrag.sh` script can automatically retrieve all database connection information (host, port, user, password), eliminating the need to manually set database credentials. + +You only need to run [install_lightrag.sh](install_lightrag.sh) like this: +```bash +export OPENAI_API_BASE= +export OPENAI_API_KEY= +bash ./install_lightrag.sh +``` + +The above commands automatically extract the database passwords from Kubernetes secrets, eliminating the need to manually set these credentials. + +After deployment, you can access the application: +```bash + 1. Run this port-forward command in your terminal: + kubectl --namespace rag port-forward svc/lightrag 9621:9621 + + 2. While the command is running, open your browser and navigate to: + http://localhost:9621 +``` + +## Configuration + +### Modifying Resource Configuration + +You can configure LightRAG's resource usage by modifying the `values.yaml` file: + +```yaml +replicaCount: 1 # Number of replicas, can be increased as needed + +resources: + limits: + cpu: 1000m # CPU limit, can be adjusted as needed + memory: 2Gi # Memory limit, can be adjusted as needed + requests: + cpu: 500m # CPU request, can be adjusted as needed + memory: 1Gi # Memory request, can be adjusted as needed +``` + +### Modifying Persistent Storage + +```yaml +persistence: + enabled: true + ragStorage: + size: 10Gi # RAG storage size, can be adjusted as needed + inputs: + size: 5Gi # Input data storage size, can be adjusted as needed +``` + +### Configuring Environment Variables + +The `env` section in the `values.yaml` file contains all environment configurations for LightRAG, similar to a `.env` file. When using helm upgrade or helm install commands, you can override these with the --set flag. + +```yaml +env: + HOST: 0.0.0.0 + PORT: 9621 + WEBUI_TITLE: Graph RAG Engine + WEBUI_DESCRIPTION: Simple and Fast Graph Based RAG System + + # LLM Configuration + LLM_BINDING: openai # LLM service provider + LLM_MODEL: gpt-4o-mini # LLM model + LLM_BINDING_HOST: # API base URL (optional) + LLM_BINDING_API_KEY: # API key + + # Embedding Configuration + EMBEDDING_BINDING: openai # Embedding service provider + EMBEDDING_MODEL: text-embedding-ada-002 # Embedding model + EMBEDDING_DIM: 1536 # Embedding dimension + EMBEDDING_BINDING_API_KEY: # API key + + # Storage Configuration + LIGHTRAG_KV_STORAGE: PGKVStorage # Key-value storage type + LIGHTRAG_VECTOR_STORAGE: PGVectorStorage # Vector storage type + LIGHTRAG_GRAPH_STORAGE: Neo4JStorage # Graph storage type + LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage # Document status storage type +``` + +## Notes + +- Ensure all necessary environment variables (API keys and database passwords) are set before deployment +- For security reasons, it's recommended to pass sensitive information using environment variables rather than writing them directly in scripts or values files +- Lightweight deployment is suitable for testing and small-scale usage, but data persistence and performance may be limited +- Full deployment (PostgreSQL + Neo4J) is recommended for production environments and large-scale usage +- For more customized configurations, please refer to the official LightRAG documentation diff --git a/k8s-deploy/databases/00-config.sh b/k8s-deploy/databases/00-config.sh new file mode 100755 index 00000000..f5186edf --- /dev/null +++ b/k8s-deploy/databases/00-config.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/scripts/common.sh" + +# Namespace configuration +NAMESPACE="rag" +# version +KB_VERSION="1.0.0-beta.48" +ADDON_CLUSTER_CHART_VERSION="1.0.0-alpha.0" +# Helm repository +HELM_REPO="https://apecloud.github.io/helm-charts" + +# Set to true to enable the database, false to disable +ENABLE_POSTGRESQL=true +ENABLE_REDIS=false +ENABLE_ELASTICSEARCH=false +ENABLE_QDRANT=false +ENABLE_MONGODB=false +ENABLE_NEO4J=true diff --git a/k8s-deploy/databases/01-prepare.sh b/k8s-deploy/databases/01-prepare.sh new file mode 100755 index 00000000..bbe30f8a --- /dev/null +++ b/k8s-deploy/databases/01-prepare.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +check_dependencies + +# Check if KubeBlocks is already installed, install it if it is not. +source "$SCRIPT_DIR/install-kubeblocks.sh" + +# Create namespaces +print "Creating namespaces..." +kubectl create namespace $NAMESPACE 2>/dev/null || true + +# Install database addons +print "Installing KubeBlocks database addons..." + +# Add and update Helm repository +print "Adding and updating KubeBlocks Helm repository..." +helm repo add kubeblocks $HELM_REPO +helm repo update +# Install database addons based on configuration +[ "$ENABLE_POSTGRESQL" = true ] && print "Installing PostgreSQL addon..." && helm upgrade --install kb-addon-postgresql kubeblocks/postgresql --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_REDIS" = true ] && print "Installing Redis addon..." && helm upgrade --install kb-addon-redis kubeblocks/redis --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_ELASTICSEARCH" = true ] && print "Installing Elasticsearch addon..." && helm upgrade --install kb-addon-elasticsearch kubeblocks/elasticsearch --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_QDRANT" = true ] && print "Installing Qdrant addon..." && helm upgrade --install kb-addon-qdrant kubeblocks/qdrant --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB addon..." && helm upgrade --install kb-addon-mongodb kubeblocks/mongodb --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j addon..." && helm upgrade --install kb-addon-neo4j kubeblocks/neo4j --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION + +print "KubeBlocks database addons installation completed!" +print "Now you can run 02-install-database.sh to install database clusters" diff --git a/k8s-deploy/databases/02-install-database.sh b/k8s-deploy/databases/02-install-database.sh new file mode 100755 index 00000000..6502ec91 --- /dev/null +++ b/k8s-deploy/databases/02-install-database.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# KubeBlocks database installation script +# Install all database clusters + +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +print "Installing database clusters..." + +# Install database clusters based on configuration +[ "$ENABLE_POSTGRESQL" = true ] && print "Installing PostgreSQL cluster..." && helm upgrade --install pg-cluster kubeblocks/postgresql-cluster -f "$SCRIPT_DIR/postgresql/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_REDIS" = true ] && print "Installing Redis cluster..." && helm upgrade --install redis-cluster kubeblocks/redis-cluster -f "$SCRIPT_DIR/redis/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_ELASTICSEARCH" = true ] && print "Installing Elasticsearch cluster..." && helm upgrade --install es-cluster kubeblocks/elasticsearch-cluster -f "$SCRIPT_DIR/elasticsearch/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_QDRANT" = true ] && print "Installing Qdrant cluster..." && helm upgrade --install qdrant-cluster kubeblocks/qdrant-cluster -f "$SCRIPT_DIR/qdrant/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB cluster..." && helm upgrade --install mongodb-cluster kubeblocks/mongodb-cluster -f "$SCRIPT_DIR/mongodb/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j cluster..." && helm upgrade --install neo4j-cluster kubeblocks/neo4j-cluster -f "$SCRIPT_DIR/neo4j/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION + +print "Database clusters installation completed!" +print "Use the following command to check the status of installed clusters:" +print "kubectl get clusters -n $NAMESPACE" diff --git a/k8s-deploy/databases/03-uninstall-database.sh b/k8s-deploy/databases/03-uninstall-database.sh new file mode 100755 index 00000000..16197909 --- /dev/null +++ b/k8s-deploy/databases/03-uninstall-database.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +print "Uninstalling database clusters..." + +# Uninstall database clusters based on configuration +[ "$ENABLE_POSTGRESQL" = true ] && print "Uninstalling PostgreSQL cluster..." && helm uninstall pg-cluster --namespace $NAMESPACE 2>/dev/null || true +[ "$ENABLE_REDIS" = true ] && print "Uninstalling Redis cluster..." && helm uninstall redis-cluster --namespace $NAMESPACE 2>/dev/null || true +[ "$ENABLE_ELASTICSEARCH" = true ] && print "Uninstalling Elasticsearch cluster..." && helm uninstall es-cluster --namespace $NAMESPACE 2>/dev/null || true +[ "$ENABLE_QDRANT" = true ] && print "Uninstalling Qdrant cluster..." && helm uninstall qdrant-cluster --namespace $NAMESPACE 2>/dev/null || true +[ "$ENABLE_MONGODB" = true ] && print "Uninstalling MongoDB cluster..." && helm uninstall mongodb-cluster --namespace $NAMESPACE 2>/dev/null || true +[ "$ENABLE_NEO4J" = true ] && print "Uninstalling Neo4j cluster..." && helm uninstall neo4j-cluster --namespace $NAMESPACE 2>/dev/null || true + +print "Database clusters uninstalled" +print "To uninstall database addons and KubeBlocks, run 04-cleanup.sh" diff --git a/k8s-deploy/databases/04-cleanup.sh b/k8s-deploy/databases/04-cleanup.sh new file mode 100755 index 00000000..2be2c049 --- /dev/null +++ b/k8s-deploy/databases/04-cleanup.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +print "Uninstalling KubeBlocks database addons..." + +# Uninstall database addons based on configuration +[ "$ENABLE_POSTGRESQL" = true ] && print "Uninstalling PostgreSQL addon..." && helm uninstall kb-addon-postgresql --namespace kb-system 2>/dev/null || true +[ "$ENABLE_REDIS" = true ] && print "Uninstalling Redis addon..." && helm uninstall kb-addon-redis --namespace kb-system 2>/dev/null || true +[ "$ENABLE_ELASTICSEARCH" = true ] && print "Uninstalling Elasticsearch addon..." && helm uninstall kb-addon-elasticsearch --namespace kb-system 2>/dev/null || true +[ "$ENABLE_QDRANT" = true ] && print "Uninstalling Qdrant addon..." && helm uninstall kb-addon-qdrant --namespace kb-system 2>/dev/null || true +[ "$ENABLE_MONGODB" = true ] && print "Uninstalling MongoDB addon..." && helm uninstall kb-addon-mongodb --namespace kb-system 2>/dev/null || true +[ "$ENABLE_NEO4J" = true ] && print "Uninstalling Neo4j addon..." && helm uninstall kb-addon-neo4j --namespace kb-system 2>/dev/null || true + +print "Database addons uninstallation completed!" + +source "$SCRIPT_DIR/uninstall-kubeblocks.sh" + +kubectl delete namespace $NAMESPACE +kubectl delete namespace kb-system + +print "KubeBlocks uninstallation completed!" diff --git a/k8s-deploy/databases/README.md b/k8s-deploy/databases/README.md new file mode 100644 index 00000000..1e0002d0 --- /dev/null +++ b/k8s-deploy/databases/README.md @@ -0,0 +1,170 @@ +# Using KubeBlocks to Deploy and Manage Databases + +Learn how to quickly deploy and manage various databases in a Kubernetes (K8s) environment through KubeBlocks. + +## Introduction to KubeBlocks + +KubeBlocks is a production-ready, open-source toolkit that runs any database--SQL, NoSQL, vector, or document--on Kubernetes. +It scales smoothly from quick dev tests to full production clusters, making it a solid choice for RAG workloads like FastGPT that need several data stores working together. + +## Prerequisites + +Make sure the following tools are installed and configured: + +* **Kubernetes cluster** + * A running Kubernetes cluster is required. + * For local development or demos you can use [Minikube](https://minikube.sigs.k8s.io/docs/start/) (needs ≥ 2 CPUs, ≥ 4 GB RAM, and Docker/VM-driver support). + * Any standard cloud or on-premises Kubernetes cluster (EKS, GKE, AKS, etc.) also works. + +* **kubectl** + * The Kubernetes command-line interface. + * Follow the official guide: [Install and Set Up kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl). + +* **Helm** (v3.x+) + * Kubernetes package manager used by the scripts below. + * Install it via the official instructions: [Installing Helm](https://helm.sh/docs/intro/install/). + +## Installing + +1. **Configure the databases you want** + Edit `00-config.sh` file. Based on your requirements, set the variable to `true` for the databases you want to install. + For example, to install PostgreSQL and Neo4j: + + ```bash + ENABLE_POSTGRESQL=true + ENABLE_REDIS=false + ENABLE_ELASTICSEARCH=false + ENABLE_QDRANT=false + ENABLE_MONGODB=false + ENABLE_NEO4J=true + ``` + +2. **Prepare the environment and install KubeBlocks add-ons** + + ```bash + bash ./01-prepare.sh + ``` + + *What the script does* + `01-prepare.sh` performs basic pre-checks (Helm, kubectl, cluster reachability), adds the KubeBlocks Helm repo, and installs any core CRDs or controllers that KubeBlocks itself needs. It also installs the addons for every database you enabled in `00-config.sh`, but **does not** create the actual database clusters yet. + +3. **(Optional) Modify database settings** + Before deployment you can edit the `values.yaml` file inside each `/` directory to change `version`, `replicas`, `CPU`, `memory`, `storage size`, etc. + +4. **Install the database clusters** + + ```bash + bash ./02-install-database.sh + ``` + + *What the script does* + `02-install-database.sh` **actually deploys the chosen databases to Kubernetes**. + + When the script completes, confirm that the clusters are up. It may take a few minutes for all the clusters to become ready, + especially if this is the first time running the script as Kubernetes needs to pull container images from registries. + You can monitor the progress using the following commands: + + ```bash + kubectl get clusters -n rag + NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE + es-cluster Delete Running 11m + mongodb-cluster mongodb Delete Running 11m + pg-cluster postgresql Delete Running 11m + qdrant-cluster qdrant Delete Running 11m + redis-cluster redis Delete Running 11m + ``` + + You can see all the Database `Pods` created by KubeBlocks. + Initially, you might see pods in `ContainerCreating` or `Pending` status - this is normal while images are being pulled and containers are starting up. + Wait until all pods show `Running` status: + + ```bash + kubectl get po -n rag + NAME READY STATUS RESTARTS AGE + es-cluster-mdit-0 2/2 Running 0 11m + mongodb-cluster-mongodb-0 2/2 Running 0 11m + pg-cluster-postgresql-0 4/4 Running 0 11m + pg-cluster-postgresql-1 4/4 Running 0 11m + qdrant-cluster-qdrant-0 2/2 Running 0 11m + redis-cluster-redis-0 2/2 Running 0 11m + ``` + + You can also check the detailed status of a specific pod if it's taking longer than expected: + + ```bash + kubectl describe pod -n rag + ``` + +## Connect to Databases + +To connect to your databases, follow these steps to identify available accounts, retrieve credentials, and establish connections: + +### 1. List Available Database Clusters + +First, view the database clusters running in your namespace: + +```bash +kubectl get cluster -n rag +``` + +### 2. Retrieve Authentication Credentials + +For PostgreSQL, retrieve the username and password from Kubernetes secrets: + +```bash +# Get PostgreSQL username +kubectl get secrets -n rag pg-cluster-postgresql-account-postgres -o jsonpath='{.data.username}' | base64 -d +# Get PostgreSQL password +kubectl get secrets -n rag pg-cluster-postgresql-account-postgres -o jsonpath='{.data.password}' | base64 -d +``` + +If you have trouble finding the correct secret name, list all secrets: + +```bash +kubectl get secrets -n rag +``` + +### 3. Port Forward to Local Machine + +Use port forwarding to access PostgreSQL from your local machine: + +```bash +# Forward PostgreSQL port (5432) to your local machine +# You can see all services with: kubectl get svc -n rag +kubectl port-forward -n rag svc/pg-cluster-postgresql-postgresql 5432:5432 +``` + +### 4. Connect Using Database Client + +Now you can connect using your preferred PostgreSQL client with the retrieved credentials: + +```bash +# Example: connecting with psql +export PGUSER=$(kubectl get secrets -n rag pg-cluster-postgresql-account-postgres -o jsonpath='{.data.username}' | base64 -d) +export PGPASSWORD=$(kubectl get secrets -n rag pg-cluster-postgresql-account-postgres -o jsonpath='{.data.password}' | base64 -d) +psql -h localhost -p 5432 -U $PGUSER +``` + +Keep the port-forwarding terminal running while you're connecting to the database. + + +## Uninstalling + +1. **Remove the database clusters** + + ```bash + bash ./03-uninstall-database.sh + ``` + + The script deletes the database clusters that were enabled in `00-config.sh`. + +2. **Clean up KubeBlocks add-ons** + + ```bash + bash ./04-cleanup.sh + ``` + + This removes the addons installed by `01-prepare.sh`. + +## Reference +* [Kubeblocks Documentation](https://kubeblocks.io/docs/preview/user_docs/overview/introduction) diff --git a/k8s-deploy/databases/elasticsearch/values.yaml b/k8s-deploy/databases/elasticsearch/values.yaml new file mode 100644 index 00000000..4563ad2c --- /dev/null +++ b/k8s-deploy/databases/elasticsearch/values.yaml @@ -0,0 +1,36 @@ +## description: The version of ElasticSearch. +## default: 8.8.2 +version: "8.8.2" + +## description: Mode for ElasticSearch +## default: multi-node +## one of: [single-node, multi-node] +mode: single-node + +## description: The number of replicas, for single-node mode, the replicas is 1, for multi-node mode, the default replicas is 3. +## default: 1 +## minimum: 1 +## maximum: 5 +replicas: 1 + +## description: CPU cores. +## default: 1 +## minimum: 0.5 +## maximum: 64 +cpu: 1 + +## description: Memory, the unit is Gi. +## default: 2 +## minimum: 1 +## maximum: 1000 +memory: 2 + +## description: Storage size, the unit is Gi. +## default: 20 +## minimum: 1 +## maximum: 10000 +storage: 5 + +extra: + terminationPolicy: Delete + disableExporter: true diff --git a/k8s-deploy/databases/install-kubeblocks.sh b/k8s-deploy/databases/install-kubeblocks.sh new file mode 100644 index 00000000..9a46e057 --- /dev/null +++ b/k8s-deploy/databases/install-kubeblocks.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +# Check dependencies +check_dependencies + +# Function for installing KubeBlocks +install_kubeblocks() { + print "Ready to install KubeBlocks." + + # Install CSI Snapshotter CRDs + kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml + kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml + kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml + + # Add and update Piraeus repository + helm repo add piraeus-charts https://piraeus.io/helm-charts/ + helm repo update + + # Install snapshot controller + helm install snapshot-controller piraeus-charts/snapshot-controller -n kb-system --create-namespace + kubectl wait --for=condition=ready pods -l app=snapshot-controller -n kb-system --timeout=120s + print_success "snapshot-controller installation complete!" + + # Install KubeBlocks CRDs + kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/v${KB_VERSION}/kubeblocks_crds.yaml + + # Add and update KubeBlocks repository + helm repo add kubeblocks $HELM_REPO + helm repo update + + # Install KubeBlocks + helm install kubeblocks kubeblocks/kubeblocks --namespace kb-system --create-namespace --version=${KB_VERSION} + + # Verify installation + print "Waiting for KubeBlocks to be ready..." + kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=kubeblocks -n kb-system --timeout=300s + print_success "KubeBlocks installation complete!" +} + +# Check if KubeBlocks is already installed +print "Checking if KubeBlocks is already installed in kb-system namespace..." +if kubectl get namespace kb-system &>/dev/null && kubectl get deployment kubeblocks -n kb-system &>/dev/null; then + print_success "KubeBlocks is already installed in kb-system namespace." +else + # Call the function to install KubeBlocks + install_kubeblocks +fi diff --git a/k8s-deploy/databases/mongodb/values.yaml b/k8s-deploy/databases/mongodb/values.yaml new file mode 100644 index 00000000..e4840a32 --- /dev/null +++ b/k8s-deploy/databases/mongodb/values.yaml @@ -0,0 +1,34 @@ +## description: Cluster version. +## default: 6.0.16 +## one of: [8.0.8, 8.0.6, 8.0.4, 7.0.19, 7.0.16, 7.0.12, 6.0.22, 6.0.20, 6.0.16, 5.0.30, 5.0.28, 4.4.29, 4.2.24, 4.0.28] +version: 6.0.16 + +## description: Cluster topology mode. +## default: standalone +## one of: [standalone, replicaset] +mode: standalone + +## description: CPU cores. +## default: 0.5 +## minimum: 0.5 +## maximum: 64 +cpu: 1 + +## description: Memory, the unit is Gi. +## default: 0.5 +## minimum: 0.5 +## maximum: 1000 +memory: 1 + +## description: Storage size, the unit is Gi. +## default: 20 +## minimum: 1 +## maximum: 10000 +storage: 20 + +## default: enabled +## one of: [enabled, disabled] +hostnetwork: "disabled" + +extra: + terminationPolicy: Delete diff --git a/k8s-deploy/databases/neo4j/values.yaml b/k8s-deploy/databases/neo4j/values.yaml new file mode 100644 index 00000000..2e26479a --- /dev/null +++ b/k8s-deploy/databases/neo4j/values.yaml @@ -0,0 +1,46 @@ +# Version +# description: Cluster version. +# default: 5.26.5 +# one of: [5.26.5, 4.4.42] +version: 5.26.5 + +# Mode +# description: Cluster topology mode. +# default: singlealone +# one of: [singlealone] +mode: singlealone + +# CPU +# description: CPU cores. +# default: 2 +# minimum: 2 +# maximum: 64 +cpu: 2 + +# Memory(Gi) +# description: Memory, the unit is Gi. +# default: 2 +# minimum: 2 +# maximum: 1000 +memory: 4 + +# Storage(Gi) +# description: Storage size, the unit is Gi. +# default: 20 +# minimum: 1 +# maximum: 10000 +storage: 20 + +# Replicas +# description: The number of replicas, for standalone mode, the replicas is 1, for replicaset mode, the default replicas is 3. +# default: 1 +# minimum: 1 +# maximum: 5 +replicas: 1 + +# Storage Class Name +# description: Storage class name of the data volume +storageClassName: "" + +extra: + terminationPolicy: Delete diff --git a/k8s-deploy/databases/postgresql/values.yaml b/k8s-deploy/databases/postgresql/values.yaml new file mode 100644 index 00000000..d706593b --- /dev/null +++ b/k8s-deploy/databases/postgresql/values.yaml @@ -0,0 +1,33 @@ +## description: service version. +## default: 15.7.0 +version: 16.4.0 + +## mode postgresql cluster topology mode replication +mode: replication + +## description: The number of replicas, for standalone mode, the replicas is 1, for replication mode, the default replicas is 2. +## default: 1 +## minimum: 1 +## maximum: 5 +replicas: 2 + +## description: CPU cores. +## default: 0.5 +## minimum: 0.5 +## maximum: 64 +cpu: 1 + +## description: Memory, the unit is Gi. +## default: 0.5 +## minimum: 0.5 +## maximum: 1000 +memory: 1 + +## description: Storage size, the unit is Gi. +## default: 20 +## minimum: 1 +## maximum: 10000 +storage: 5 + +## terminationPolicy define Cluster termination policy. One of DoNotTerminate, Delete, WipeOut. +terminationPolicy: Delete diff --git a/k8s-deploy/databases/qdrant/values.yaml b/k8s-deploy/databases/qdrant/values.yaml new file mode 100644 index 00000000..c49d9960 --- /dev/null +++ b/k8s-deploy/databases/qdrant/values.yaml @@ -0,0 +1,31 @@ +## description: The version of Qdrant. +## default: 1.10.0 +version: 1.10.0 + +## description: The number of replicas. +## default: 1 +## minimum: 1 +## maximum: 16 +replicas: 1 + +## description: CPU cores. +## default: 1 +## minimum: 0.5 +## maximum: 64 +cpu: 1 + +## description: Memory, the unit is Gi. +## default: 2 +## minimum: 0.5 +## maximum: 1000 +memory: 1 + +## description: Storage size, the unit is Gi. +## default: 20 +## minimum: 1 +## maximum: 10000 +storage: 20 + +## customized default values to override kblib chart's values +extra: + terminationPolicy: Delete diff --git a/k8s-deploy/databases/redis/values.yaml b/k8s-deploy/databases/redis/values.yaml new file mode 100644 index 00000000..356e35f7 --- /dev/null +++ b/k8s-deploy/databases/redis/values.yaml @@ -0,0 +1,34 @@ +## description: Cluster version. +## default: 7.2.7 +version: 7.2.7 + +## description: Cluster topology mode. +## default: replication +## one of: [standalone, replication, cluster, replication-twemproxy] +mode: standalone + +## description: The number of replicas, for standalone mode, the replicas is 1, for replication mode, the default replicas is 2. +## default: 1 +## minimum: 1 +## maximum: 5 +replicas: 1 + +## description: CPU cores. +## default: 0.5 +## minimum: 0.5 +## maximum: 64 +cpu: 0.5 + +## description: Memory, the unit is Gi. +## default: 0.5 +## minimum: 0.5 +## maximum: 1000 +memory: 1 + +## description: Storage size, the unit is Gi. +## default: 20 +## minimum: 1 +## maximum: 10000 +storage: 20 +extra: + disableExporter: true diff --git a/k8s-deploy/databases/scripts/common.sh b/k8s-deploy/databases/scripts/common.sh new file mode 100644 index 00000000..3d5369fb --- /dev/null +++ b/k8s-deploy/databases/scripts/common.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +print_title() { + echo "============================================" + echo "$1" + echo "============================================" +} + +print_success() { + echo "✅ $1" +} + +print_error() { + echo "❌ $1" +} + +print_warning() { + echo "⚠️ $1" +} + +print_info() { + echo "🔹 $1" +} + +print() { + echo "$1" +} + +# Check dependencies +check_dependencies(){ + print "Checking dependencies..." + command -v kubectl >/dev/null 2>&1 || { print "Error: kubectl command not found"; exit 1; } + command -v helm >/dev/null 2>&1 || { print "Error: helm command not found"; exit 1; } + + # Check if Kubernetes is available + print "Checking if Kubernetes is available..." + kubectl cluster-info &>/dev/null + if [ $? -ne 0 ]; then + print "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." + exit 1 + fi + print "Kubernetes cluster is accessible." +} diff --git a/k8s-deploy/databases/uninstall-kubeblocks.sh b/k8s-deploy/databases/uninstall-kubeblocks.sh new file mode 100644 index 00000000..a752462b --- /dev/null +++ b/k8s-deploy/databases/uninstall-kubeblocks.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# Load configuration file +source "$SCRIPT_DIR/00-config.sh" + +# Check dependencies +print "Checking dependencies..." +command -v kubectl >/dev/null 2>&1 || { print "Error: kubectl command not found"; exit 1; } +command -v helm >/dev/null 2>&1 || { print "Error: helm command not found"; exit 1; } + +print "Checking if Kubernetes is available..." +if ! kubectl cluster-info &>/dev/null; then + print "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." + exit 1 +fi +print "Kubernetes cluster is accessible." + +print "Checking if KubeBlocks is installed in kb-system namespace..." +if ! kubectl get namespace kb-system &>/dev/null; then + print "KubeBlocks is not installed in kb-system namespace." + exit 0 +fi + +# Function for uninstalling KubeBlocks +uninstall_kubeblocks() { + print "Uninstalling KubeBlocks..." + + # Uninstall KubeBlocks Helm chart + helm uninstall kubeblocks -n kb-system + + # Uninstall snapshot controller + helm uninstall snapshot-controller -n kb-system + + # Delete KubeBlocks CRDs + kubectl delete -f https://github.com/apecloud/kubeblocks/releases/download/v${KB_VERSION}/kubeblocks_crds.yaml --ignore-not-found=true + + # Delete CSI Snapshotter CRDs + kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml --ignore-not-found=true + kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml --ignore-not-found=true + kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml --ignore-not-found=true + + # Delete the kb-system namespace + print "Waiting for resources to be removed..." + kubectl delete namespace kb-system --timeout=180s + + print "KubeBlocks has been successfully uninstalled!" +} + +# Call the function to uninstall KubeBlocks +uninstall_kubeblocks diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh new file mode 100755 index 00000000..2411356b --- /dev/null +++ b/k8s-deploy/install_lightrag.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +NAMESPACE=rag + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Check and set environment variables +if [ -z "$OPENAI_API_KEY" ]; then + echo "OPENAI_API_KEY environment variable is not set" + read -p "Enter your OpenAI API key: " OPENAI_API_KEY + if [ -z "$OPENAI_API_KEY" ]; then + echo "Error: OPENAI_API_KEY must be provided" + exit 1 + fi + export OPENAI_API_KEY=$OPENAI_API_KEY +fi + +if [ -z "$OPENAI_API_BASE" ]; then + echo "OPENAI_API_BASE environment variable is not set, will use default value" + read -p "Enter OpenAI API base URL (press Enter to skip if not needed): " OPENAI_API_BASE + export OPENAI_API_BASE=$OPENAI_API_BASE +fi + +# Check if databases are already installed, install them if not +echo "Checking database installation status..." +if ! kubectl get clusters -n rag pg-cluster &> /dev/null || ! kubectl get clusters -n rag neo4j-cluster &> /dev/null; then + echo "Databases not installed or incompletely installed, will install required databases first..." + + # Install KubeBlocks (if not already installed) + echo "Preparing to install KubeBlocks and required components..." + bash "$SCRIPT_DIR/databases/01-prepare.sh" + + # Install database clusters + echo "Installing database clusters..." + bash "$SCRIPT_DIR/databases/02-install-database.sh" + + # Wait for databases to be ready + echo "Waiting for databases to be ready..." + TIMEOUT=600 # Set timeout to 10 minutes + START_TIME=$(date +%s) + + while true; do + CURRENT_TIME=$(date +%s) + ELAPSED=$((CURRENT_TIME - START_TIME)) + + if [ $ELAPSED -gt $TIMEOUT ]; then + echo "Timeout waiting for databases to be ready. Please check database status manually and try again" + exit 1 + fi + + PG_STATUS=$(kubectl get clusters -n rag pg-cluster -o jsonpath='{.status.phase}' 2>/dev/null) + NEO4J_STATUS=$(kubectl get clusters -n rag neo4j-cluster -o jsonpath='{.status.phase}' 2>/dev/null) + + if [ "$PG_STATUS" == "Running" ] && [ "$NEO4J_STATUS" == "Running" ]; then + echo "Databases are ready, continuing with LightRAG deployment..." + break + fi + + echo "Databases preparing... PostgreSQL: $PG_STATUS, Neo4J: $NEO4J_STATUS" + sleep 10 + done +else + echo "Databases already installed, proceeding directly to LightRAG deployment..." +fi + +# Get database passwords from Kubernetes secrets +echo "Retrieving database credentials from Kubernetes secrets..." +POSTGRES_PASSWORD=$(kubectl get secrets -n rag pg-cluster-postgresql-account-postgres -o jsonpath='{.data.password}' | base64 -d) +if [ -z "$POSTGRES_PASSWORD" ]; then + echo "Error: Could not retrieve PostgreSQL password. Make sure PostgreSQL is deployed and the secret exists." + exit 1 +fi +export POSTGRES_PASSWORD=$POSTGRES_PASSWORD + +NEO4J_PASSWORD=$(kubectl get secrets -n rag neo4j-cluster-neo4j-account-neo4j -o jsonpath='{.data.password}' | base64 -d) +if [ -z "$NEO4J_PASSWORD" ]; then + echo "Error: Could not retrieve Neo4J password. Make sure Neo4J is deployed and the secret exists." + exit 1 +fi +export NEO4J_PASSWORD=$NEO4J_PASSWORD + +echo "Deploying production LightRAG (using external databases)..." + +if ! kubectl get namespace rag &> /dev/null; then + echo "creating namespace 'rag'..." + kubectl create namespace rag +fi + +helm upgrade --install lightrag . \ + --namespace $NAMESPACE \ + --set-string env.POSTGRES_PASSWORD=$POSTGRES_PASSWORD \ + --set-string env.NEO4J_PASSWORD=$NEO4J_PASSWORD \ + --set-string env.LLM_BINDING=openai \ + --set-string env.LLM_MODEL=gpt-4o-mini \ + --set-string env.LLM_BINDING_HOST=$OPENAI_API_BASE \ + --set-string env.LLM_BINDING_API_KEY=$OPENAI_API_KEY \ + --set-string env.EMBEDDING_BINDING=openai \ + --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ + --set-string env.EMBEDDING_DIM=1536 \ + --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY + +# Wait for LightRAG pod to be ready +echo "Waiting for LightRAG pod to be ready..." +kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=60s -n rag diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh new file mode 100755 index 00000000..5e82b393 --- /dev/null +++ b/k8s-deploy/install_lightrag_dev.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +NAMESPACE=rag + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +if [ -z "$OPENAI_API_KEY" ]; then + echo "OPENAI_API_KEY environment variable is not set" + read -p "Enter your OpenAI API key: " OPENAI_API_KEY + if [ -z "$OPENAI_API_KEY" ]; then + echo "Error: OPENAI_API_KEY must be provided" + exit 1 + fi + export OPENAI_API_KEY=$OPENAI_API_KEY +fi + +if [ -z "$OPENAI_API_BASE" ]; then + echo "OPENAI_API_BASE environment variable is not set, will use default value" + read -p "Enter OpenAI API base URL (press Enter to skip if not needed): " OPENAI_API_BASE + export OPENAI_API_BASE=$OPENAI_API_BASE +fi + +required_env_vars=("OPENAI_API_BASE" "OPENAI_API_KEY") + +for var in "${required_env_vars[@]}"; do + if [ -z "${!var}" ]; then + echo "Error: $var environment variable is not set" + exit 1 + fi +done + +echo "Environment variables check passed" + +if ! kubectl get namespace rag &> /dev/null; then + echo "creating namespace 'rag'..." + kubectl create namespace rag +fi + +helm upgrade --install lightrag-dev $SCRIPT_DIR \ + --namespace rag \ + --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ + --set-string env.LIGHTRAG_VECTOR_STORAGE=NanoVectorDBStorage \ + --set-string env.LIGHTRAG_GRAPH_STORAGE=NetworkXStorage \ + --set-string env.LIGHTRAG_DOC_STATUS_STORAGE=JsonDocStatusStorage \ + --set-string env.LLM_BINDING=openai \ + --set-string env.LLM_MODEL=gpt-4o-mini \ + --set-string env.LLM_BINDING_HOST=$OPENAI_API_BASE \ + --set-string env.LLM_BINDING_API_KEY=$OPENAI_API_KEY \ + --set-string env.EMBEDDING_BINDING=openai \ + --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ + --set-string env.EMBEDDING_DIM=1536 \ + --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY + +# Wait for LightRAG pod to be ready +echo "Waiting for LightRAG pod to be ready..." +kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag-dev --timeout=60s -n rag diff --git a/k8s-deploy/lightrag/.helmignore b/k8s-deploy/lightrag/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/k8s-deploy/lightrag/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/k8s-deploy/lightrag/Chart.yaml b/k8s-deploy/lightrag/Chart.yaml new file mode 100644 index 00000000..19d68d9b --- /dev/null +++ b/k8s-deploy/lightrag/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: lightrag +description: A Helm chart for LightRAG, an efficient and lightweight RAG system +type: application +version: 0.1.0 +appVersion: "1.0.0" +maintainers: + - name: LightRAG Team + - name: earayu + email: earayu@gmail.com diff --git a/k8s-deploy/lightrag/templates/NOTES.txt b/k8s-deploy/lightrag/templates/NOTES.txt new file mode 100644 index 00000000..6b81aca0 --- /dev/null +++ b/k8s-deploy/lightrag/templates/NOTES.txt @@ -0,0 +1,38 @@ +=========================================== + LightRAG has been successfully deployed! +=========================================== + +View application logs: + kubectl logs -f --namespace {{ .Release.Namespace }} deploy/{{ include "lightrag.fullname" . }} + +=========================================== + +Access the application: +{{- if contains "NodePort" .Values.service.type }} + Run these commands to get access information: + ----------------------------------------- + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "lightrag.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo "LightRAG is accessible at: http://$NODE_IP:$NODE_PORT" + ----------------------------------------- +{{- else if contains "LoadBalancer" .Values.service.type }} + Run these commands to get access information (external IP may take a minute to assign): + ----------------------------------------- + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "lightrag.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}") + echo "LightRAG is accessible at: http://$SERVICE_IP:{{ .Values.service.port }}" + ----------------------------------------- + If SERVICE_IP is empty, retry the command or check service status with: + kubectl get svc --namespace {{ .Release.Namespace }} {{ include "lightrag.fullname" . }} +{{- else if contains "ClusterIP" .Values.service.type }} + For development environments, to access LightRAG from your local machine: + + 1. Run this port-forward command in your terminal: + kubectl --namespace {{ .Release.Namespace }} port-forward svc/{{ include "lightrag.fullname" . }} {{ .Values.service.port }}:{{ .Values.env.PORT }} + + 2. While the command is running, open your browser and navigate to: + http://localhost:{{ .Values.service.port }} + + Note: To stop port-forwarding, press Ctrl+C in the terminal. +{{- end }} + +=========================================== diff --git a/k8s-deploy/lightrag/templates/_helpers.tpl b/k8s-deploy/lightrag/templates/_helpers.tpl new file mode 100644 index 00000000..2b2c23ae --- /dev/null +++ b/k8s-deploy/lightrag/templates/_helpers.tpl @@ -0,0 +1,42 @@ +{{/* +Application name +*/}} +{{- define "lightrag.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Full application name +*/}} +{{- define "lightrag.fullname" -}} +{{- default .Release.Name .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "lightrag.labels" -}} +app.kubernetes.io/name: {{ include "lightrag.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "lightrag.selectorLabels" -}} +app.kubernetes.io/name: {{ include "lightrag.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +.env file content +*/}} +{{- define "lightrag.envContent" -}} +{{- $first := true -}} +{{- range $key, $val := .Values.env -}} +{{- if not $first -}}{{- "\n" -}}{{- end -}} +{{- $first = false -}} +{{ $key }}={{ $val }} +{{- end -}} +{{- end -}} diff --git a/k8s-deploy/lightrag/templates/deployment.yaml b/k8s-deploy/lightrag/templates/deployment.yaml new file mode 100644 index 00000000..f30571fd --- /dev/null +++ b/k8s-deploy/lightrag/templates/deployment.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "lightrag.fullname" . }} + labels: + {{- include "lightrag.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "lightrag.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include "lightrag.envContent" . | sha256sum }} + labels: + {{- include "lightrag.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: {{ .Values.env.PORT }} + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: rag-storage + mountPath: /app/data/rag_storage + - name: inputs + mountPath: /app/data/inputs + - name: env-file + mountPath: /app/.env + subPath: .env + volumes: + - name: env-file + secret: + secretName: {{ include "lightrag.fullname" . }}-env + {{- if .Values.persistence.enabled }} + - name: rag-storage + persistentVolumeClaim: + claimName: {{ include "lightrag.fullname" . }}-rag-storage + - name: inputs + persistentVolumeClaim: + claimName: {{ include "lightrag.fullname" . }}-inputs + {{- else }} + - name: rag-storage + emptyDir: {} + - name: inputs + emptyDir: {} + {{- end }} diff --git a/k8s-deploy/lightrag/templates/pvc.yaml b/k8s-deploy/lightrag/templates/pvc.yaml new file mode 100644 index 00000000..570474bc --- /dev/null +++ b/k8s-deploy/lightrag/templates/pvc.yaml @@ -0,0 +1,28 @@ +{{- if .Values.persistence.enabled }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "lightrag.fullname" . }}-rag-storage + labels: + {{- include "lightrag.labels" . | nindent 4 }} +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.persistence.ragStorage.size }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "lightrag.fullname" . }}-inputs + labels: + {{- include "lightrag.labels" . | nindent 4 }} +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.persistence.inputs.size }} +{{- end }} diff --git a/k8s-deploy/lightrag/templates/secret.yaml b/k8s-deploy/lightrag/templates/secret.yaml new file mode 100644 index 00000000..8f403ab8 --- /dev/null +++ b/k8s-deploy/lightrag/templates/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "lightrag.fullname" . }}-env + labels: + {{- include "lightrag.labels" . | nindent 4 }} +type: Opaque +stringData: + .env: |- + {{- include "lightrag.envContent" . | nindent 4 }} diff --git a/k8s-deploy/lightrag/templates/service.yaml b/k8s-deploy/lightrag/templates/service.yaml new file mode 100644 index 00000000..e5525e18 --- /dev/null +++ b/k8s-deploy/lightrag/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "lightrag.fullname" . }} + labels: + {{- include "lightrag.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.env.PORT }} + protocol: TCP + name: http + selector: + {{- include "lightrag.selectorLabels" . | nindent 4 }} diff --git a/k8s-deploy/lightrag/values.yaml b/k8s-deploy/lightrag/values.yaml new file mode 100644 index 00000000..e19ae669 --- /dev/null +++ b/k8s-deploy/lightrag/values.yaml @@ -0,0 +1,53 @@ +replicaCount: 1 + +image: + repository: ghcr.io/hkuds/lightrag + tag: latest + +service: + type: ClusterIP + port: 9621 + +resources: + limits: + cpu: 1000m + memory: 2Gi + requests: + cpu: 500m + memory: 1Gi + +persistence: + enabled: true + ragStorage: + size: 10Gi + inputs: + size: 5Gi + +env: + HOST: 0.0.0.0 + PORT: 9621 + WEBUI_TITLE: Graph RAG Engine + WEBUI_DESCRIPTION: Simple and Fast Graph Based RAG System + LLM_BINDING: openai + LLM_MODEL: gpt-4o-mini + LLM_BINDING_HOST: + LLM_BINDING_API_KEY: + EMBEDDING_BINDING: openai + EMBEDDING_MODEL: text-embedding-ada-002 + EMBEDDING_DIM: 1536 + EMBEDDING_BINDING_API_KEY: + LIGHTRAG_KV_STORAGE: PGKVStorage + LIGHTRAG_VECTOR_STORAGE: PGVectorStorage + LIGHTRAG_GRAPH_STORAGE: Neo4JStorage + LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage + # Replace with your POSTGRES credentials + POSTGRES_HOST: pg-cluster-postgresql-postgresql + POSTGRES_PORT: 5432 + POSTGRES_USER: postgres + POSTGRES_PASSWORD: + POSTGRES_DATABASE: postgres + POSTGRES_WORKSPACE: default + # Replace with your NEO4J credentials + NEO4J_URI: neo4j://neo4j-cluster-neo4j:7687 + NEO4J_USERNAME: neo4j + NEO4J_PASSWORD: diff --git a/k8s-deploy/uninstall_lightrag.sh b/k8s-deploy/uninstall_lightrag.sh new file mode 100644 index 00000000..e4806b77 --- /dev/null +++ b/k8s-deploy/uninstall_lightrag.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +NAMESPACE=rag +helm uninstall lightrag --namespace $NAMESPACE diff --git a/k8s-deploy/uninstall_lightrag_dev.sh b/k8s-deploy/uninstall_lightrag_dev.sh new file mode 100644 index 00000000..cac01abd --- /dev/null +++ b/k8s-deploy/uninstall_lightrag_dev.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +NAMESPACE=rag +helm uninstall lightrag-dev --namespace $NAMESPACE From 1bcb1c4ad753c4a1e1ff3a7e14461688eef4d569 Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 18:17:02 +0800 Subject: [PATCH 03/14] feat: add helm chart --- k8s-deploy/install_lightrag.sh | 17 +++++++++++++++++ k8s-deploy/install_lightrag_dev.sh | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index 2411356b..a326ff76 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -5,6 +5,23 @@ NAMESPACE=rag # Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +check_dependencies(){ + echo "Checking dependencies..." + command -v kubectl >/dev/null 2>&1 || { echo "Error: kubectl command not found"; exit 1; } + command -v helm >/dev/null 2>&1 || { echo "Error: helm command not found"; exit 1; } + + # Check if Kubernetes is available + echo "Checking if Kubernetes is available..." + kubectl cluster-info &>/dev/null + if [ $? -ne 0 ]; then + echo "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." + exit 1 + fi + echo "Kubernetes cluster is accessible." +} + +check_dependencies + # Check and set environment variables if [ -z "$OPENAI_API_KEY" ]; then echo "OPENAI_API_KEY environment variable is not set" diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index 5e82b393..ba28d7ed 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -5,6 +5,23 @@ NAMESPACE=rag # Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +check_dependencies(){ + echo "Checking dependencies..." + command -v kubectl >/dev/null 2>&1 || { echo "Error: kubectl command not found"; exit 1; } + command -v helm >/dev/null 2>&1 || { echo "Error: helm command not found"; exit 1; } + + # Check if Kubernetes is available + echo "Checking if Kubernetes is available..." + kubectl cluster-info &>/dev/null + if [ $? -ne 0 ]; then + echo "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." + exit 1 + fi + echo "Kubernetes cluster is accessible." +} + +check_dependencies + if [ -z "$OPENAI_API_KEY" ]; then echo "OPENAI_API_KEY environment variable is not set" read -p "Enter your OpenAI API key: " OPENAI_API_KEY From 1429b36495724e979c999f826a2969d30605a926 Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 18:29:40 +0800 Subject: [PATCH 04/14] feat: add helm chart --- k8s-deploy/install_lightrag.sh | 2 +- k8s-deploy/install_lightrag_dev.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index a326ff76..67b0564f 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -104,7 +104,7 @@ if ! kubectl get namespace rag &> /dev/null; then kubectl create namespace rag fi -helm upgrade --install lightrag . \ +helm upgrade --install lightrag $SCRIPT_DIR/lightrag \ --namespace $NAMESPACE \ --set-string env.POSTGRES_PASSWORD=$POSTGRES_PASSWORD \ --set-string env.NEO4J_PASSWORD=$NEO4J_PASSWORD \ diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index ba28d7ed..4d573eb5 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -54,7 +54,7 @@ if ! kubectl get namespace rag &> /dev/null; then kubectl create namespace rag fi -helm upgrade --install lightrag-dev $SCRIPT_DIR \ +helm upgrade --install lightrag-dev $SCRIPT_DIR/lightrag \ --namespace rag \ --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ --set-string env.LIGHTRAG_VECTOR_STORAGE=NanoVectorDBStorage \ From 777fe12bc0df2a04b49a654da2ef004877f57161 Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 19:01:18 +0800 Subject: [PATCH 05/14] feat: add helm chart --- k8s-deploy/databases/01-prepare.sh | 2 +- k8s-deploy/databases/02-install-database.sh | 2 +- k8s-deploy/databases/03-uninstall-database.sh | 2 +- k8s-deploy/databases/04-cleanup.sh | 4 +-- k8s-deploy/databases/install-kubeblocks.sh | 4 +-- k8s-deploy/databases/scripts/common.sh | 2 +- k8s-deploy/databases/uninstall-kubeblocks.sh | 1 - k8s-deploy/install_lightrag.sh | 29 ++++++++++++++----- k8s-deploy/install_lightrag_dev.sh | 2 -- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/k8s-deploy/databases/01-prepare.sh b/k8s-deploy/databases/01-prepare.sh index bbe30f8a..509467f8 100755 --- a/k8s-deploy/databases/01-prepare.sh +++ b/k8s-deploy/databases/01-prepare.sh @@ -29,5 +29,5 @@ helm repo update [ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB addon..." && helm upgrade --install kb-addon-mongodb kubeblocks/mongodb --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION [ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j addon..." && helm upgrade --install kb-addon-neo4j kubeblocks/neo4j --namespace kb-system --version $ADDON_CLUSTER_CHART_VERSION -print "KubeBlocks database addons installation completed!" +print_success "KubeBlocks database addons installation completed!" print "Now you can run 02-install-database.sh to install database clusters" diff --git a/k8s-deploy/databases/02-install-database.sh b/k8s-deploy/databases/02-install-database.sh index 6502ec91..39acfede 100755 --- a/k8s-deploy/databases/02-install-database.sh +++ b/k8s-deploy/databases/02-install-database.sh @@ -19,6 +19,6 @@ print "Installing database clusters..." [ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB cluster..." && helm upgrade --install mongodb-cluster kubeblocks/mongodb-cluster -f "$SCRIPT_DIR/mongodb/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION [ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j cluster..." && helm upgrade --install neo4j-cluster kubeblocks/neo4j-cluster -f "$SCRIPT_DIR/neo4j/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -print "Database clusters installation completed!" +print_success "Database clusters installation completed!" print "Use the following command to check the status of installed clusters:" print "kubectl get clusters -n $NAMESPACE" diff --git a/k8s-deploy/databases/03-uninstall-database.sh b/k8s-deploy/databases/03-uninstall-database.sh index 16197909..61635590 100755 --- a/k8s-deploy/databases/03-uninstall-database.sh +++ b/k8s-deploy/databases/03-uninstall-database.sh @@ -16,5 +16,5 @@ print "Uninstalling database clusters..." [ "$ENABLE_MONGODB" = true ] && print "Uninstalling MongoDB cluster..." && helm uninstall mongodb-cluster --namespace $NAMESPACE 2>/dev/null || true [ "$ENABLE_NEO4J" = true ] && print "Uninstalling Neo4j cluster..." && helm uninstall neo4j-cluster --namespace $NAMESPACE 2>/dev/null || true -print "Database clusters uninstalled" +print_success "Database clusters uninstalled" print "To uninstall database addons and KubeBlocks, run 04-cleanup.sh" diff --git a/k8s-deploy/databases/04-cleanup.sh b/k8s-deploy/databases/04-cleanup.sh index 2be2c049..4c467c17 100755 --- a/k8s-deploy/databases/04-cleanup.sh +++ b/k8s-deploy/databases/04-cleanup.sh @@ -16,11 +16,11 @@ print "Uninstalling KubeBlocks database addons..." [ "$ENABLE_MONGODB" = true ] && print "Uninstalling MongoDB addon..." && helm uninstall kb-addon-mongodb --namespace kb-system 2>/dev/null || true [ "$ENABLE_NEO4J" = true ] && print "Uninstalling Neo4j addon..." && helm uninstall kb-addon-neo4j --namespace kb-system 2>/dev/null || true -print "Database addons uninstallation completed!" +print_success "Database addons uninstallation completed!" source "$SCRIPT_DIR/uninstall-kubeblocks.sh" kubectl delete namespace $NAMESPACE kubectl delete namespace kb-system -print "KubeBlocks uninstallation completed!" +print_success "KubeBlocks uninstallation completed!" diff --git a/k8s-deploy/databases/install-kubeblocks.sh b/k8s-deploy/databases/install-kubeblocks.sh index 9a46e057..6e41ddfd 100644 --- a/k8s-deploy/databases/install-kubeblocks.sh +++ b/k8s-deploy/databases/install-kubeblocks.sh @@ -23,7 +23,7 @@ install_kubeblocks() { # Install snapshot controller helm install snapshot-controller piraeus-charts/snapshot-controller -n kb-system --create-namespace - kubectl wait --for=condition=ready pods -l app=snapshot-controller -n kb-system --timeout=120s + kubectl wait --for=condition=ready pods -l app.kubernetes.io/name=snapshot-controller -n kb-system --timeout=60s print_success "snapshot-controller installation complete!" # Install KubeBlocks CRDs @@ -38,7 +38,7 @@ install_kubeblocks() { # Verify installation print "Waiting for KubeBlocks to be ready..." - kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=kubeblocks -n kb-system --timeout=300s + kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=kubeblocks -n kb-system --timeout=120s print_success "KubeBlocks installation complete!" } diff --git a/k8s-deploy/databases/scripts/common.sh b/k8s-deploy/databases/scripts/common.sh index 3d5369fb..3ffb4b08 100644 --- a/k8s-deploy/databases/scripts/common.sh +++ b/k8s-deploy/databases/scripts/common.sh @@ -39,5 +39,5 @@ check_dependencies(){ print "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." exit 1 fi - print "Kubernetes cluster is accessible." + print_success "Kubernetes cluster is accessible." } diff --git a/k8s-deploy/databases/uninstall-kubeblocks.sh b/k8s-deploy/databases/uninstall-kubeblocks.sh index a752462b..dd38ac67 100644 --- a/k8s-deploy/databases/uninstall-kubeblocks.sh +++ b/k8s-deploy/databases/uninstall-kubeblocks.sh @@ -15,7 +15,6 @@ if ! kubectl cluster-info &>/dev/null; then print "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." exit 1 fi -print "Kubernetes cluster is accessible." print "Checking if KubeBlocks is installed in kb-system namespace..." if ! kubectl get namespace kb-system &>/dev/null; then diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index 67b0564f..fd88e0ec 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -54,7 +54,7 @@ if ! kubectl get clusters -n rag pg-cluster &> /dev/null || ! kubectl get cluste # Wait for databases to be ready echo "Waiting for databases to be ready..." - TIMEOUT=600 # Set timeout to 10 minutes + TIMEOUT=300 # Set timeout to 5 minutes START_TIME=$(date +%s) while true; do @@ -66,19 +66,32 @@ if ! kubectl get clusters -n rag pg-cluster &> /dev/null || ! kubectl get cluste exit 1 fi - PG_STATUS=$(kubectl get clusters -n rag pg-cluster -o jsonpath='{.status.phase}' 2>/dev/null) - NEO4J_STATUS=$(kubectl get clusters -n rag neo4j-cluster -o jsonpath='{.status.phase}' 2>/dev/null) - - if [ "$PG_STATUS" == "Running" ] && [ "$NEO4J_STATUS" == "Running" ]; then - echo "Databases are ready, continuing with LightRAG deployment..." + # Use kubectl wait to check if both databases are ready + if kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n rag --timeout=10s &> /dev/null && + kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n rag --timeout=10s &> /dev/null; then + echo "Database pods are ready, continuing with LightRAG deployment..." break fi - echo "Databases preparing... PostgreSQL: $PG_STATUS, Neo4J: $NEO4J_STATUS" + echo "Waiting for database pods to be ready..." sleep 10 done else - echo "Databases already installed, proceeding directly to LightRAG deployment..." + echo "Databases already installed, checking if database pods are ready..." + + # Verify that pods are ready before proceeding + echo "Waiting for database pods to be ready..." + if ! kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n rag --timeout=60s; then + echo "PostgreSQL pods are not ready. Please check database status manually." + exit 1 + fi + + if ! kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n rag --timeout=60s; then + echo "Neo4j pods are not ready. Please check database status manually." + exit 1 + fi + + echo "Database pods are ready, proceeding with LightRAG deployment..." fi # Get database passwords from Kubernetes secrets diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index 4d573eb5..a1167dc3 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -47,8 +47,6 @@ for var in "${required_env_vars[@]}"; do fi done -echo "Environment variables check passed" - if ! kubectl get namespace rag &> /dev/null; then echo "creating namespace 'rag'..." kubectl create namespace rag From fe2df486235424fca78b835f824669f87b8a367d Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 22:42:45 +0800 Subject: [PATCH 06/14] feat: add helm chart --- k8s-deploy/databases/00-config.sh | 8 +- k8s-deploy/databases/01-prepare.sh | 6 +- k8s-deploy/databases/02-install-database.sh | 60 +++++++++--- k8s-deploy/databases/03-uninstall-database.sh | 4 +- k8s-deploy/databases/04-cleanup.sh | 6 +- k8s-deploy/databases/install-kubeblocks.sh | 4 +- k8s-deploy/databases/uninstall-kubeblocks.sh | 4 +- k8s-deploy/install_lightrag.sh | 95 +++++-------------- k8s-deploy/install_lightrag_dev.sh | 1 - k8s-deploy/lightrag/templates/deployment.yaml | 9 ++ k8s-deploy/lightrag/values.yaml | 5 + 11 files changed, 105 insertions(+), 97 deletions(-) diff --git a/k8s-deploy/databases/00-config.sh b/k8s-deploy/databases/00-config.sh index f5186edf..9431a3d3 100755 --- a/k8s-deploy/databases/00-config.sh +++ b/k8s-deploy/databases/00-config.sh @@ -1,8 +1,8 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/scripts/common.sh" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$DATABASE_SCRIPT_DIR/scripts/common.sh" # Namespace configuration NAMESPACE="rag" @@ -15,7 +15,7 @@ HELM_REPO="https://apecloud.github.io/helm-charts" # Set to true to enable the database, false to disable ENABLE_POSTGRESQL=true ENABLE_REDIS=false -ENABLE_ELASTICSEARCH=false ENABLE_QDRANT=false -ENABLE_MONGODB=false ENABLE_NEO4J=true +ENABLE_ELASTICSEARCH=false +ENABLE_MONGODB=false diff --git a/k8s-deploy/databases/01-prepare.sh b/k8s-deploy/databases/01-prepare.sh index 509467f8..f43257a4 100755 --- a/k8s-deploy/databases/01-prepare.sh +++ b/k8s-deploy/databases/01-prepare.sh @@ -1,14 +1,14 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" check_dependencies # Check if KubeBlocks is already installed, install it if it is not. -source "$SCRIPT_DIR/install-kubeblocks.sh" +source "$DATABASE_SCRIPT_DIR/install-kubeblocks.sh" # Create namespaces print "Creating namespaces..." diff --git a/k8s-deploy/databases/02-install-database.sh b/k8s-deploy/databases/02-install-database.sh index 39acfede..f19a08d7 100755 --- a/k8s-deploy/databases/02-install-database.sh +++ b/k8s-deploy/databases/02-install-database.sh @@ -1,23 +1,61 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - -# KubeBlocks database installation script -# Install all database clusters +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" print "Installing database clusters..." # Install database clusters based on configuration -[ "$ENABLE_POSTGRESQL" = true ] && print "Installing PostgreSQL cluster..." && helm upgrade --install pg-cluster kubeblocks/postgresql-cluster -f "$SCRIPT_DIR/postgresql/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -[ "$ENABLE_REDIS" = true ] && print "Installing Redis cluster..." && helm upgrade --install redis-cluster kubeblocks/redis-cluster -f "$SCRIPT_DIR/redis/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -[ "$ENABLE_ELASTICSEARCH" = true ] && print "Installing Elasticsearch cluster..." && helm upgrade --install es-cluster kubeblocks/elasticsearch-cluster -f "$SCRIPT_DIR/elasticsearch/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -[ "$ENABLE_QDRANT" = true ] && print "Installing Qdrant cluster..." && helm upgrade --install qdrant-cluster kubeblocks/qdrant-cluster -f "$SCRIPT_DIR/qdrant/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -[ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB cluster..." && helm upgrade --install mongodb-cluster kubeblocks/mongodb-cluster -f "$SCRIPT_DIR/mongodb/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION -[ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j cluster..." && helm upgrade --install neo4j-cluster kubeblocks/neo4j-cluster -f "$SCRIPT_DIR/neo4j/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_POSTGRESQL" = true ] && print "Installing PostgreSQL cluster..." && helm upgrade --install pg-cluster kubeblocks/postgresql-cluster -f "$DATABASE_SCRIPT_DIR/postgresql/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_REDIS" = true ] && print "Installing Redis cluster..." && helm upgrade --install redis-cluster kubeblocks/redis-cluster -f "$DATABASE_SCRIPT_DIR/redis/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_ELASTICSEARCH" = true ] && print "Installing Elasticsearch cluster..." && helm upgrade --install es-cluster kubeblocks/elasticsearch-cluster -f "$DATABASE_SCRIPT_DIR/elasticsearch/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_QDRANT" = true ] && print "Installing Qdrant cluster..." && helm upgrade --install qdrant-cluster kubeblocks/qdrant-cluster -f "$DATABASE_SCRIPT_DIR/qdrant/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB cluster..." && helm upgrade --install mongodb-cluster kubeblocks/mongodb-cluster -f "$DATABASE_SCRIPT_DIR/mongodb/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION +[ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j cluster..." && helm upgrade --install neo4j-cluster kubeblocks/neo4j-cluster -f "$DATABASE_SCRIPT_DIR/neo4j/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION + +# Wait for databases to be ready +print "Waiting for databases to be ready..." +TIMEOUT=600 # Set timeout to 10 minutes +START_TIME=$(date +%s) + +while true; do + CURRENT_TIME=$(date +%s) + ELAPSED=$((CURRENT_TIME - START_TIME)) + + if [ $ELAPSED -gt $TIMEOUT ]; then + print_error "Timeout waiting for databases to be ready. Please check database status manually and try again" + exit 1 + fi + + # Build wait conditions for enabled databases + WAIT_CONDITIONS=() + [ "$ENABLE_POSTGRESQL" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n $NAMESPACE --timeout=10s") + [ "$ENABLE_REDIS" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=redis-cluster -n $NAMESPACE --timeout=10s") + [ "$ENABLE_ELASTICSEARCH" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=es-cluster -n $NAMESPACE --timeout=10s") + [ "$ENABLE_QDRANT" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=qdrant-cluster -n $NAMESPACE --timeout=10s") + [ "$ENABLE_MONGODB" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=mongodb-cluster -n $NAMESPACE --timeout=10s") + [ "$ENABLE_NEO4J" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n $NAMESPACE --timeout=10s") + + # Check if all enabled databases are ready + ALL_READY=true + for CONDITION in "${WAIT_CONDITIONS[@]}"; do + if ! eval "$CONDITION &> /dev/null"; then + ALL_READY=false + break + fi + done + + if [ "$ALL_READY" = true ]; then + print "All database pods are ready, continuing with deployment..." + break + fi + + print "Waiting for database pods to be ready (${ELAPSED}s elapsed)..." + sleep 10 +done print_success "Database clusters installation completed!" print "Use the following command to check the status of installed clusters:" diff --git a/k8s-deploy/databases/03-uninstall-database.sh b/k8s-deploy/databases/03-uninstall-database.sh index 61635590..be0503c5 100755 --- a/k8s-deploy/databases/03-uninstall-database.sh +++ b/k8s-deploy/databases/03-uninstall-database.sh @@ -1,10 +1,10 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" print "Uninstalling database clusters..." diff --git a/k8s-deploy/databases/04-cleanup.sh b/k8s-deploy/databases/04-cleanup.sh index 4c467c17..12493501 100755 --- a/k8s-deploy/databases/04-cleanup.sh +++ b/k8s-deploy/databases/04-cleanup.sh @@ -1,10 +1,10 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" print "Uninstalling KubeBlocks database addons..." @@ -18,7 +18,7 @@ print "Uninstalling KubeBlocks database addons..." print_success "Database addons uninstallation completed!" -source "$SCRIPT_DIR/uninstall-kubeblocks.sh" +source "$DATABASE_SCRIPT_DIR/uninstall-kubeblocks.sh" kubectl delete namespace $NAMESPACE kubectl delete namespace kb-system diff --git a/k8s-deploy/databases/install-kubeblocks.sh b/k8s-deploy/databases/install-kubeblocks.sh index 6e41ddfd..838413ac 100644 --- a/k8s-deploy/databases/install-kubeblocks.sh +++ b/k8s-deploy/databases/install-kubeblocks.sh @@ -1,9 +1,9 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" # Check dependencies check_dependencies diff --git a/k8s-deploy/databases/uninstall-kubeblocks.sh b/k8s-deploy/databases/uninstall-kubeblocks.sh index dd38ac67..3b5ffd1f 100644 --- a/k8s-deploy/databases/uninstall-kubeblocks.sh +++ b/k8s-deploy/databases/uninstall-kubeblocks.sh @@ -1,9 +1,9 @@ #!/bin/bash # Get the directory where this script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load configuration file -source "$SCRIPT_DIR/00-config.sh" +source "$DATABASE_SCRIPT_DIR/00-config.sh" # Check dependencies print "Checking dependencies..." diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index fd88e0ec..a1051a48 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -2,27 +2,8 @@ NAMESPACE=rag -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -check_dependencies(){ - echo "Checking dependencies..." - command -v kubectl >/dev/null 2>&1 || { echo "Error: kubectl command not found"; exit 1; } - command -v helm >/dev/null 2>&1 || { echo "Error: helm command not found"; exit 1; } - - # Check if Kubernetes is available - echo "Checking if Kubernetes is available..." - kubectl cluster-info &>/dev/null - if [ $? -ne 0 ]; then - echo "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster." - exit 1 - fi - echo "Kubernetes cluster is accessible." -} - -check_dependencies - -# Check and set environment variables if [ -z "$OPENAI_API_KEY" ]; then echo "OPENAI_API_KEY environment variable is not set" read -p "Enter your OpenAI API key: " OPENAI_API_KEY @@ -39,59 +20,24 @@ if [ -z "$OPENAI_API_BASE" ]; then export OPENAI_API_BASE=$OPENAI_API_BASE fi -# Check if databases are already installed, install them if not -echo "Checking database installation status..." -if ! kubectl get clusters -n rag pg-cluster &> /dev/null || ! kubectl get clusters -n rag neo4j-cluster &> /dev/null; then - echo "Databases not installed or incompletely installed, will install required databases first..." +# Install KubeBlocks (if not already installed) +echo "Preparing to install KubeBlocks and required components..." +bash "$SCRIPT_DIR/databases/01-prepare.sh" - # Install KubeBlocks (if not already installed) - echo "Preparing to install KubeBlocks and required components..." - bash "$SCRIPT_DIR/databases/01-prepare.sh" +# Install database clusters +echo "Installing database clusters..." +bash "$SCRIPT_DIR/databases/02-install-database.sh" - # Install database clusters - echo "Installing database clusters..." - bash "$SCRIPT_DIR/databases/02-install-database.sh" - - # Wait for databases to be ready - echo "Waiting for databases to be ready..." - TIMEOUT=300 # Set timeout to 5 minutes - START_TIME=$(date +%s) - - while true; do - CURRENT_TIME=$(date +%s) - ELAPSED=$((CURRENT_TIME - START_TIME)) - - if [ $ELAPSED -gt $TIMEOUT ]; then - echo "Timeout waiting for databases to be ready. Please check database status manually and try again" - exit 1 +# Create vector extension in PostgreSQL if enabled +if [ "$ENABLE_POSTGRESQL" = true ]; then + print "Waiting for PostgreSQL pods to be ready..." + if kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n $NAMESPACE --timeout=300s; then + print "Creating vector extension in PostgreSQL..." + kubectl exec -it $(kubectl get pods -l kubeblocks.io/role=primary,app.kubernetes.io/instance=pg-cluster -n $NAMESPACE -o name) -n $NAMESPACE -- psql -c "CREATE EXTENSION vector;" + print_success "Vector extension created successfully." + else + print "Warning: PostgreSQL pods not ready within timeout. Vector extension not created." fi - - # Use kubectl wait to check if both databases are ready - if kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n rag --timeout=10s &> /dev/null && - kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n rag --timeout=10s &> /dev/null; then - echo "Database pods are ready, continuing with LightRAG deployment..." - break - fi - - echo "Waiting for database pods to be ready..." - sleep 10 - done -else - echo "Databases already installed, checking if database pods are ready..." - - # Verify that pods are ready before proceeding - echo "Waiting for database pods to be ready..." - if ! kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n rag --timeout=60s; then - echo "PostgreSQL pods are not ready. Please check database status manually." - exit 1 - fi - - if ! kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n rag --timeout=60s; then - echo "Neo4j pods are not ready. Please check database status manually." - exit 1 - fi - - echo "Database pods are ready, proceeding with LightRAG deployment..." fi # Get database passwords from Kubernetes secrets @@ -110,6 +56,13 @@ if [ -z "$NEO4J_PASSWORD" ]; then fi export NEO4J_PASSWORD=$NEO4J_PASSWORD +#REDIS_PASSWORD=$(kubectl get secrets -n rag redis-cluster-redis-account-default -o jsonpath='{.data.password}' | base64 -d) +#if [ -z "$REDIS_PASSWORD" ]; then +# echo "Error: Could not retrieve Redis password. Make sure Redis is deployed and the secret exists." +# exit 1 +#fi +#export REDIS_PASSWORD=$REDIS_PASSWORD + echo "Deploying production LightRAG (using external databases)..." if ! kubectl get namespace rag &> /dev/null; then @@ -129,7 +82,11 @@ helm upgrade --install lightrag $SCRIPT_DIR/lightrag \ --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ --set-string env.EMBEDDING_DIM=1536 \ --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY +# --set-string env.REDIS_URI="redis://default:${REDIS_PASSWORD}@redis-cluster-redis-redis:6379" # Wait for LightRAG pod to be ready echo "Waiting for LightRAG pod to be ready..." kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=60s -n rag + +#echo "Current LightRAG Config: " +#kubectl get secrets lightrag-env -o jsonpath='{.data.\.env}' -n rag | base64 -d diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index a1167dc3..7d3c3f37 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -2,7 +2,6 @@ NAMESPACE=rag -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" check_dependencies(){ diff --git a/k8s-deploy/lightrag/templates/deployment.yaml b/k8s-deploy/lightrag/templates/deployment.yaml index f30571fd..fe63c1ac 100644 --- a/k8s-deploy/lightrag/templates/deployment.yaml +++ b/k8s-deploy/lightrag/templates/deployment.yaml @@ -24,6 +24,15 @@ spec: - name: http containerPort: {{ .Values.env.PORT }} protocol: TCP + readinessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 10 + periodSeconds: 5 + timeoutSeconds: 2 + successThreshold: 1 + failureThreshold: 3 resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/k8s-deploy/lightrag/values.yaml b/k8s-deploy/lightrag/values.yaml index e19ae669..fb1bbe31 100644 --- a/k8s-deploy/lightrag/values.yaml +++ b/k8s-deploy/lightrag/values.yaml @@ -38,6 +38,8 @@ env: EMBEDDING_BINDING_API_KEY: LIGHTRAG_KV_STORAGE: PGKVStorage LIGHTRAG_VECTOR_STORAGE: PGVectorStorage +# LIGHTRAG_KV_STORAGE: RedisKVStorage +# LIGHTRAG_VECTOR_STORAGE: QdrantVectorDBStorage LIGHTRAG_GRAPH_STORAGE: Neo4JStorage LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage # Replace with your POSTGRES credentials @@ -51,3 +53,6 @@ env: NEO4J_URI: neo4j://neo4j-cluster-neo4j:7687 NEO4J_USERNAME: neo4j NEO4J_PASSWORD: + # Replace with your Qdrant credentials + QDRANT_URL: http://qdrant-cluster-qdrant-qdrant:6333 + # REDIS_URI: redis://default:${REDIS_PASSWORD}@redis-cluster-redis-redis:6379 From 3742d2a02693cc42d9b80e3778e6632649998322 Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 22:55:18 +0800 Subject: [PATCH 07/14] feat: add helm chart --- k8s-deploy/install_lightrag.sh | 15 +++++++++++---- k8s-deploy/install_lightrag_dev.sh | 12 +++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index a1051a48..d8bad096 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -85,8 +85,15 @@ helm upgrade --install lightrag $SCRIPT_DIR/lightrag \ # --set-string env.REDIS_URI="redis://default:${REDIS_PASSWORD}@redis-cluster-redis-redis:6379" # Wait for LightRAG pod to be ready -echo "Waiting for LightRAG pod to be ready..." +echo "" +echo "Waiting for lightrag pod to be ready..." kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=60s -n rag - -#echo "Current LightRAG Config: " -#kubectl get secrets lightrag-env -o jsonpath='{.data.\.env}' -n rag | base64 -d +echo "lightrag pod is ready" +echo "" +echo "Running Port-Forward:" +echo " kubectl --namespace rag port-forward svc/lightrag 9621:9621" +echo "===========================================" +echo "" +echo "✅ You can visit LightRAG at: http://localhost:9621" +echo "" +kubectl --namespace rag port-forward svc/lightrag 9621:9621 diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index 7d3c3f37..f3f9b03c 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -67,5 +67,15 @@ helm upgrade --install lightrag-dev $SCRIPT_DIR/lightrag \ --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY # Wait for LightRAG pod to be ready -echo "Waiting for LightRAG pod to be ready..." +echo "" +echo "Waiting for lightrag-dev pod to be ready..." kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag-dev --timeout=60s -n rag +echo "lightrag-dev pod is ready" +echo "" +echo "Running Port-Forward:" +echo " kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621" +echo "===========================================" +echo "" +echo "✅ You can visit LightRAG at: http://localhost:9621" +echo "" +kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621 From 25a6306ae005038997ce9266b28a89d4bbfe2b5a Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 23:06:11 +0800 Subject: [PATCH 08/14] feat: add helm chart --- k8s-deploy/install_lightrag.sh | 20 ++++++++------------ k8s-deploy/uninstall_lightrag.sh | 0 2 files changed, 8 insertions(+), 12 deletions(-) mode change 100644 => 100755 k8s-deploy/uninstall_lightrag.sh diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index d8bad096..5bafe6ce 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -21,23 +21,19 @@ if [ -z "$OPENAI_API_BASE" ]; then fi # Install KubeBlocks (if not already installed) -echo "Preparing to install KubeBlocks and required components..." bash "$SCRIPT_DIR/databases/01-prepare.sh" # Install database clusters -echo "Installing database clusters..." bash "$SCRIPT_DIR/databases/02-install-database.sh" # Create vector extension in PostgreSQL if enabled -if [ "$ENABLE_POSTGRESQL" = true ]; then - print "Waiting for PostgreSQL pods to be ready..." - if kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n $NAMESPACE --timeout=300s; then - print "Creating vector extension in PostgreSQL..." - kubectl exec -it $(kubectl get pods -l kubeblocks.io/role=primary,app.kubernetes.io/instance=pg-cluster -n $NAMESPACE -o name) -n $NAMESPACE -- psql -c "CREATE EXTENSION vector;" - print_success "Vector extension created successfully." - else - print "Warning: PostgreSQL pods not ready within timeout. Vector extension not created." - fi +print "Waiting for PostgreSQL pods to be ready..." +if kubectl wait --for=condition=ready pods -l kubeblocks.io/role=primary,app.kubernetes.io/instance=pg-cluster -n $NAMESPACE --timeout=300s; then + print "Creating vector extension in PostgreSQL..." + kubectl exec -it $(kubectl get pods -l kubeblocks.io/role=primary,app.kubernetes.io/instance=pg-cluster -n $NAMESPACE -o name) -n $NAMESPACE -- psql -c "CREATE EXTENSION vector;" + print_success "Vector extension created successfully." +else + print "Warning: PostgreSQL pods not ready within timeout. Vector extension not created." fi # Get database passwords from Kubernetes secrets @@ -87,7 +83,7 @@ helm upgrade --install lightrag $SCRIPT_DIR/lightrag \ # Wait for LightRAG pod to be ready echo "" echo "Waiting for lightrag pod to be ready..." -kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=60s -n rag +kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=120s -n rag echo "lightrag pod is ready" echo "" echo "Running Port-Forward:" diff --git a/k8s-deploy/uninstall_lightrag.sh b/k8s-deploy/uninstall_lightrag.sh old mode 100644 new mode 100755 From 780d74970a901b6bf2e27a8566a0446deb11617b Mon Sep 17 00:00:00 2001 From: earayu Date: Mon, 19 May 2025 23:07:24 +0800 Subject: [PATCH 09/14] feat: change sh script mode --- k8s-deploy/databases/install-kubeblocks.sh | 0 k8s-deploy/databases/scripts/common.sh | 0 k8s-deploy/databases/uninstall-kubeblocks.sh | 0 k8s-deploy/uninstall_lightrag_dev.sh | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 k8s-deploy/databases/install-kubeblocks.sh mode change 100644 => 100755 k8s-deploy/databases/scripts/common.sh mode change 100644 => 100755 k8s-deploy/databases/uninstall-kubeblocks.sh mode change 100644 => 100755 k8s-deploy/uninstall_lightrag_dev.sh diff --git a/k8s-deploy/databases/install-kubeblocks.sh b/k8s-deploy/databases/install-kubeblocks.sh old mode 100644 new mode 100755 diff --git a/k8s-deploy/databases/scripts/common.sh b/k8s-deploy/databases/scripts/common.sh old mode 100644 new mode 100755 diff --git a/k8s-deploy/databases/uninstall-kubeblocks.sh b/k8s-deploy/databases/uninstall-kubeblocks.sh old mode 100644 new mode 100755 diff --git a/k8s-deploy/uninstall_lightrag_dev.sh b/k8s-deploy/uninstall_lightrag_dev.sh old mode 100644 new mode 100755 From 03073b7ea1bee14f80eaf8e6e763ee0b486f8382 Mon Sep 17 00:00:00 2001 From: earayu Date: Tue, 20 May 2025 10:49:35 +0800 Subject: [PATCH 10/14] feat: update README --- k8s-deploy/README.md | 86 ++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/k8s-deploy/README.md b/k8s-deploy/README.md index 9a3d070a..85392421 100644 --- a/k8s-deploy/README.md +++ b/k8s-deploy/README.md @@ -4,7 +4,7 @@ This is the Helm chart for LightRAG, used to deploy LightRAG services on a Kuber There are two recommended deployment methods for LightRAG: 1. **Lightweight Deployment**: Using built-in lightweight storage, suitable for testing and small-scale usage -2. **Full Deployment**: Using external databases (such as PostgreSQL and Neo4J), suitable for production environments and large-scale usage +2. **Production Deployment**: Using external databases (such as PostgreSQL and Neo4J), suitable for production environments and large-scale usage ## Prerequisites @@ -16,19 +16,31 @@ Make sure the following tools are installed and configured: * Any standard cloud or on-premises Kubernetes cluster (EKS, GKE, AKS, etc.) also works. * **kubectl** - * The Kubernetes command-line interface. + * The Kubernetes command-line tool for managing your cluster. * Follow the official guide: [Install and Set Up kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl). * **Helm** (v3.x+) - * Kubernetes package manager used by the scripts below. + * Kubernetes package manager used to install LightRAG. * Install it via the official instructions: [Installing Helm](https://helm.sh/docs/intro/install/). - ## Lightweight Deployment (No External Databases Required) -Uses built-in lightweight storage components with no need to configure external databases: +This deployment option uses built-in lightweight storage components that are perfect for testing, demos, or small-scale usage scenarios. No external database configuration is required. + +You can deploy LightRAG using either the provided convenience script or direct Helm commands. Both methods configure the same environment variables defined in the `lightrag/values.yaml` file. + +### Using the convenience script (recommended): ```bash +export OPENAI_API_BASE= +export OPENAI_API_KEY= +bash ./install_lightrag_dev.sh +``` + +### Or using Helm directly: + +```bash +# You can override any env param you want helm upgrade --install lightrag ./lightrag \ --namespace rag \ --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ @@ -45,82 +57,68 @@ helm upgrade --install lightrag ./lightrag \ --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY ``` -You can refer to: [install_lightrag_dev.sh](install_lightrag_dev.sh) +### Accessing the application: -You can use it directly like this: ```bash -export OPENAI_API_BASE= -export OPENAI_API_KEY= -bash ./install_lightrag_dev.sh -``` -Then you can Access the application -```bash - 1. Run this port-forward command in your terminal: - kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621 +# 1. Run this port-forward command in your terminal: +kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621 - 2. While the command is running, open your browser and navigate to: - http://localhost:9621 +# 2. While the command is running, open your browser and navigate to: +# http://localhost:9621 ``` -## Full Deployment (Using External Databases) +## Production Deployment (Using External Databases) ### 1. Install Databases > You can skip this step if you've already prepared databases. Detailed information can be found in: [README.md](databases%2FREADME.md). We recommend KubeBlocks for database deployment. KubeBlocks is a cloud-native database operator that makes it easy to run any database on Kubernetes at production scale. -FastGPT also use KubeBlocks for their database infrastructure. First, install KubeBlocks and KubeBlocks-Addons (skip if already installed): ```bash bash ./databases/01-prepare.sh ``` -Then install the required databases. By default, this will install PostgreSQL and Neo4J, but you can modify [00-config.sh](databases%2F00-config.sh) to select different databases based on your needs. KubeBlocks supports various databases including MongoDB, Qdrant, Redis, and more. +Then install the required databases. By default, this will install PostgreSQL and Neo4J, but you can modify [00-config.sh](databases%2F00-config.sh) to select different databases based on your needs: ```bash bash ./databases/02-install-database.sh ``` -When the script completes, confirm that the clusters are up. It may take a few minutes for all the clusters to become ready, - especially if this is the first time running the script as Kubernetes needs to pull container images from registries. - You can monitor the progress using the following commands: +Verify that the clusters are up and running: ```bash kubectl get clusters -n rag -NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE -neo4j-cluster Delete Running 39s -pg-cluster postgresql Delete Creating 42s -``` -You can see all the Database `Pods` created by KubeBlocks. - Initially, you might see pods in `ContainerCreating` or `Pending` status - this is normal while images are being pulled and containers are starting up. - Wait until all pods show `Running` status: -```bash +# Expected output: +# NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE +# neo4j-cluster Delete Running 39s +# pg-cluster postgresql Delete Running 42s + kubectl get po -n rag -NAME READY STATUS RESTARTS AGE -neo4j-cluster-neo4j-0 1/1 Running 0 58s -pg-cluster-postgresql-0 4/4 Running 0 59s -pg-cluster-postgresql-1 4/4 Running 0 59s +# Expected output: +# NAME READY STATUS RESTARTS AGE +# neo4j-cluster-neo4j-0 1/1 Running 0 58s +# pg-cluster-postgresql-0 4/4 Running 0 59s +# pg-cluster-postgresql-1 4/4 Running 0 59s ``` ### 2. Install LightRAG LightRAG and its databases are deployed within the same Kubernetes cluster, making configuration straightforward. -When using KubeBlocks to provide PostgreSQL and Neo4J database services, the `install_lightrag.sh` script can automatically retrieve all database connection information (host, port, user, password), eliminating the need to manually set database credentials. +The installation script automatically retrieves all database connection information from KubeBlocks, eliminating the need to manually set database credentials: -You only need to run [install_lightrag.sh](install_lightrag.sh) like this: ```bash export OPENAI_API_BASE= export OPENAI_API_KEY= bash ./install_lightrag.sh ``` -The above commands automatically extract the database passwords from Kubernetes secrets, eliminating the need to manually set these credentials. +### Accessing the application: -After deployment, you can access the application: ```bash - 1. Run this port-forward command in your terminal: - kubectl --namespace rag port-forward svc/lightrag 9621:9621 +# 1. Run this port-forward command in your terminal: +kubectl --namespace rag port-forward svc/lightrag 9621:9621 - 2. While the command is running, open your browser and navigate to: - http://localhost:9621 +# 2. While the command is running, open your browser and navigate to: +# http://localhost:9621 ``` ## Configuration @@ -187,5 +185,5 @@ env: - Ensure all necessary environment variables (API keys and database passwords) are set before deployment - For security reasons, it's recommended to pass sensitive information using environment variables rather than writing them directly in scripts or values files - Lightweight deployment is suitable for testing and small-scale usage, but data persistence and performance may be limited -- Full deployment (PostgreSQL + Neo4J) is recommended for production environments and large-scale usage +- Production deployment (PostgreSQL + Neo4J) is recommended for production environments and large-scale usage - For more customized configurations, please refer to the official LightRAG documentation From 86d0c24276beb7ae78f1e9b63ef836a743bbbe5f Mon Sep 17 00:00:00 2001 From: earayu Date: Tue, 20 May 2025 11:26:03 +0800 Subject: [PATCH 11/14] feat: update script --- k8s-deploy/install_lightrag.sh | 2 +- k8s-deploy/install_lightrag_dev.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index 5bafe6ce..caa3d79b 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -6,7 +6,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" if [ -z "$OPENAI_API_KEY" ]; then echo "OPENAI_API_KEY environment variable is not set" - read -p "Enter your OpenAI API key: " OPENAI_API_KEY + read -s -p "Enter your OpenAI API key: " OPENAI_API_KEY if [ -z "$OPENAI_API_KEY" ]; then echo "Error: OPENAI_API_KEY must be provided" exit 1 diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index f3f9b03c..daaa6b55 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -21,9 +21,9 @@ check_dependencies(){ check_dependencies -if [ -z "$OPENAI_API_KEY" ]; then +if [ -z "$OPENAI_API_KEY2" ]; then echo "OPENAI_API_KEY environment variable is not set" - read -p "Enter your OpenAI API key: " OPENAI_API_KEY + read -s -p "Enter your OpenAI API key: " OPENAI_API_KEY if [ -z "$OPENAI_API_KEY" ]; then echo "Error: OPENAI_API_KEY must be provided" exit 1 From acd628596ac73a88b814c81fc5ee106af6a4f625 Mon Sep 17 00:00:00 2001 From: earayu Date: Tue, 20 May 2025 11:26:31 +0800 Subject: [PATCH 12/14] feat: update script --- k8s-deploy/install_lightrag_dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index daaa6b55..a7db7db0 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -21,7 +21,7 @@ check_dependencies(){ check_dependencies -if [ -z "$OPENAI_API_KEY2" ]; then +if [ -z "$OPENAI_API_KEY" ]; then echo "OPENAI_API_KEY environment variable is not set" read -s -p "Enter your OpenAI API key: " OPENAI_API_KEY if [ -z "$OPENAI_API_KEY" ]; then From 655b73e32d986e2d7e8ab3ac9e7b052aa6bd812b Mon Sep 17 00:00:00 2001 From: earayu Date: Tue, 20 May 2025 14:14:51 +0800 Subject: [PATCH 13/14] feat: update script --- k8s-deploy/install_lightrag.sh | 2 +- k8s-deploy/install_lightrag_dev.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s-deploy/install_lightrag.sh b/k8s-deploy/install_lightrag.sh index caa3d79b..763521e7 100755 --- a/k8s-deploy/install_lightrag.sh +++ b/k8s-deploy/install_lightrag.sh @@ -83,7 +83,7 @@ helm upgrade --install lightrag $SCRIPT_DIR/lightrag \ # Wait for LightRAG pod to be ready echo "" echo "Waiting for lightrag pod to be ready..." -kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=120s -n rag +kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag --timeout=300s -n rag echo "lightrag pod is ready" echo "" echo "Running Port-Forward:" diff --git a/k8s-deploy/install_lightrag_dev.sh b/k8s-deploy/install_lightrag_dev.sh index a7db7db0..3316f8a2 100755 --- a/k8s-deploy/install_lightrag_dev.sh +++ b/k8s-deploy/install_lightrag_dev.sh @@ -69,7 +69,7 @@ helm upgrade --install lightrag-dev $SCRIPT_DIR/lightrag \ # Wait for LightRAG pod to be ready echo "" echo "Waiting for lightrag-dev pod to be ready..." -kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag-dev --timeout=60s -n rag +kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=lightrag-dev --timeout=300s -n rag echo "lightrag-dev pod is ready" echo "" echo "Running Port-Forward:" From 7a41141ca94f7dc99b8eccca2c496036d40330a7 Mon Sep 17 00:00:00 2001 From: earayu Date: Tue, 20 May 2025 22:58:33 +0800 Subject: [PATCH 14/14] feat: update README --- k8s-deploy/README-zh.md | 191 ++++++++++++++++++++++++++++++++++++++++ k8s-deploy/README.md | 2 + 2 files changed, 193 insertions(+) create mode 100644 k8s-deploy/README-zh.md diff --git a/k8s-deploy/README-zh.md b/k8s-deploy/README-zh.md new file mode 100644 index 00000000..e5eb697d --- /dev/null +++ b/k8s-deploy/README-zh.md @@ -0,0 +1,191 @@ +# LightRAG Helm Chart + +这是用于在Kubernetes集群上部署LightRAG服务的Helm chart。 + +LightRAG有两种推荐的部署方法: +1. **轻量级部署**:使用内置轻量级存储,适合测试和小规模使用 +2. **生产环境部署**:使用外部数据库(如PostgreSQL和Neo4J),适合生产环境和大规模使用 + +> 如果您想要部署过程的视频演示,可以查看[bilibili](https://www.bilibili.com/video/BV1bUJazBEq2/)上的视频教程,对于喜欢视觉指导的用户可能会有所帮助。 + +## 前提条件 + +确保安装和配置了以下工具: + +* **Kubernetes集群** + * 需要一个运行中的Kubernetes集群。 + * 对于本地开发或演示,可以使用[Minikube](https://minikube.sigs.k8s.io/docs/start/)(需要≥2个CPU,≥4GB内存,以及Docker/VM驱动支持)。 + * 任何标准的云端或本地Kubernetes集群(EKS、GKE、AKS等)也可以使用。 + +* **kubectl** + * Kubernetes命令行工具,用于管理集群。 + * 按照官方指南安装:[安装和设置kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)。 + +* **Helm**(v3.x+) + * Kubernetes包管理器,用于安装LightRAG。 + * 通过官方指南安装:[安装Helm](https://helm.sh/docs/intro/install/)。 + +## 轻量级部署(无需外部数据库) + +这种部署选项使用内置的轻量级存储组件,非常适合测试、演示或小规模使用场景。无需外部数据库配置。 + +您可以使用提供的便捷脚本或直接使用Helm命令部署LightRAG。两种方法都配置了`lightrag/values.yaml`文件中定义的相同环境变量。 + +### 使用便捷脚本(推荐): + +```bash +export OPENAI_API_BASE=<您的OPENAI_API_BASE> +export OPENAI_API_KEY=<您的OPENAI_API_KEY> +bash ./install_lightrag_dev.sh +``` + +### 或直接使用Helm: + +```bash +# 您可以覆盖任何想要的环境参数 +helm upgrade --install lightrag ./lightrag \ + --namespace rag \ + --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ + --set-string env.LIGHTRAG_VECTOR_STORAGE=NanoVectorDBStorage \ + --set-string env.LIGHTRAG_GRAPH_STORAGE=NetworkXStorage \ + --set-string env.LIGHTRAG_DOC_STATUS_STORAGE=JsonDocStatusStorage \ + --set-string env.LLM_BINDING=openai \ + --set-string env.LLM_MODEL=gpt-4o-mini \ + --set-string env.LLM_BINDING_HOST=$OPENAI_API_BASE \ + --set-string env.LLM_BINDING_API_KEY=$OPENAI_API_KEY \ + --set-string env.EMBEDDING_BINDING=openai \ + --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ + --set-string env.EMBEDDING_DIM=1536 \ + --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY +``` + +### 访问应用程序: + +```bash +# 1. 在终端中运行此端口转发命令: +kubectl --namespace rag port-forward svc/lightrag-dev 9621:9621 + +# 2. 当命令运行时,打开浏览器并导航到: +# http://localhost:9621 +``` + +## 生产环境部署(使用外部数据库) + +### 1. 安装数据库 +> 如果您已经准备好了数据库,可以跳过此步骤。详细信息可以在:[README.md](databases%2FREADME.md)中找到。 + +我们推荐使用KubeBlocks进行数据库部署。KubeBlocks是一个云原生数据库操作符,可以轻松地在Kubernetes上以生产规模运行任何数据库。 + +首先,安装KubeBlocks和KubeBlocks-Addons(如已安装可跳过): +```bash +bash ./databases/01-prepare.sh +``` + +然后安装所需的数据库。默认情况下,这将安装PostgreSQL和Neo4J,但您可以修改[00-config.sh](databases%2F00-config.sh)以根据需要选择不同的数据库: +```bash +bash ./databases/02-install-database.sh +``` + +验证集群是否正在运行: +```bash +kubectl get clusters -n rag +# 预期输出: +# NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE +# neo4j-cluster Delete Running 39s +# pg-cluster postgresql Delete Running 42s + +kubectl get po -n rag +# 预期输出: +# NAME READY STATUS RESTARTS AGE +# neo4j-cluster-neo4j-0 1/1 Running 0 58s +# pg-cluster-postgresql-0 4/4 Running 0 59s +# pg-cluster-postgresql-1 4/4 Running 0 59s +``` + +### 2. 安装LightRAG + +LightRAG及其数据库部署在同一Kubernetes集群中,使配置变得简单。 +安装脚本会自动从KubeBlocks获取所有数据库连接信息,无需手动设置数据库凭证: + +```bash +export OPENAI_API_BASE=<您的OPENAI_API_BASE> +export OPENAI_API_KEY=<您的OPENAI_API_KEY> +bash ./install_lightrag.sh +``` + +### 访问应用程序: + +```bash +# 1. 在终端中运行此端口转发命令: +kubectl --namespace rag port-forward svc/lightrag 9621:9621 + +# 2. 当命令运行时,打开浏览器并导航到: +# http://localhost:9621 +``` + +## 配置 + +### 修改资源配置 + +您可以通过修改`values.yaml`文件来配置LightRAG的资源使用: + +```yaml +replicaCount: 1 # 副本数量,可根据需要增加 + +resources: + limits: + cpu: 1000m # CPU限制,可根据需要调整 + memory: 2Gi # 内存限制,可根据需要调整 + requests: + cpu: 500m # CPU请求,可根据需要调整 + memory: 1Gi # 内存请求,可根据需要调整 +``` + +### 修改持久存储 + +```yaml +persistence: + enabled: true + ragStorage: + size: 10Gi # RAG存储大小,可根据需要调整 + inputs: + size: 5Gi # 输入数据存储大小,可根据需要调整 +``` + +### 配置环境变量 + +`values.yaml`文件中的`env`部分包含LightRAG的所有环境配置,类似于`.env`文件。当使用helm upgrade或helm install命令时,可以使用--set标志覆盖这些变量。 + +```yaml +env: + HOST: 0.0.0.0 + PORT: 9621 + WEBUI_TITLE: Graph RAG Engine + WEBUI_DESCRIPTION: Simple and Fast Graph Based RAG System + + # LLM配置 + LLM_BINDING: openai # LLM服务提供商 + LLM_MODEL: gpt-4o-mini # LLM模型 + LLM_BINDING_HOST: # API基础URL(可选) + LLM_BINDING_API_KEY: # API密钥 + + # 嵌入配置 + EMBEDDING_BINDING: openai # 嵌入服务提供商 + EMBEDDING_MODEL: text-embedding-ada-002 # 嵌入模型 + EMBEDDING_DIM: 1536 # 嵌入维度 + EMBEDDING_BINDING_API_KEY: # API密钥 + + # 存储配置 + LIGHTRAG_KV_STORAGE: PGKVStorage # 键值存储类型 + LIGHTRAG_VECTOR_STORAGE: PGVectorStorage # 向量存储类型 + LIGHTRAG_GRAPH_STORAGE: Neo4JStorage # 图存储类型 + LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage # 文档状态存储类型 +``` + +## 注意事项 + +- 在部署前确保设置了所有必要的环境变量(API密钥和数据库密码) +- 出于安全原因,建议使用环境变量传递敏感信息,而不是直接写入脚本或values文件 +- 轻量级部署适合测试和小规模使用,但数据持久性和性能可能有限 +- 生产环境部署(PostgreSQL + Neo4J)推荐用于生产环境和大规模使用 +- 有关更多自定义配置,请参考LightRAG官方文档 diff --git a/k8s-deploy/README.md b/k8s-deploy/README.md index 85392421..cc1f2720 100644 --- a/k8s-deploy/README.md +++ b/k8s-deploy/README.md @@ -6,6 +6,8 @@ There are two recommended deployment methods for LightRAG: 1. **Lightweight Deployment**: Using built-in lightweight storage, suitable for testing and small-scale usage 2. **Production Deployment**: Using external databases (such as PostgreSQL and Neo4J), suitable for production environments and large-scale usage +> If you'd like a video walkthrough of the deployment process, feel free to check out this optional [video tutorial](https://youtu.be/JW1z7fzeKTw?si=vPzukqqwmdzq9Q4q) on YouTube. It might help clarify some steps for those who prefer visual guidance. + ## Prerequisites Make sure the following tools are installed and configured: