feat: add helm chart

This commit is contained in:
earayu 2025-05-19 22:42:45 +08:00
parent 777fe12bc0
commit fe2df48623
11 changed files with 105 additions and 97 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 )"
source "$SCRIPT_DIR/scripts/common.sh" source "$DATABASE_SCRIPT_DIR/scripts/common.sh"
# Namespace configuration # Namespace configuration
NAMESPACE="rag" NAMESPACE="rag"
@ -15,7 +15,7 @@ HELM_REPO="https://apecloud.github.io/helm-charts"
# Set to true to enable the database, false to disable # Set to true to enable the database, false to disable
ENABLE_POSTGRESQL=true ENABLE_POSTGRESQL=true
ENABLE_REDIS=false ENABLE_REDIS=false
ENABLE_ELASTICSEARCH=false
ENABLE_QDRANT=false ENABLE_QDRANT=false
ENABLE_MONGODB=false
ENABLE_NEO4J=true ENABLE_NEO4J=true
ENABLE_ELASTICSEARCH=false
ENABLE_MONGODB=false

View File

@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
check_dependencies check_dependencies
# Check if KubeBlocks is already installed, install it if it is not. # 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 # Create namespaces
print "Creating namespaces..." print "Creating namespaces..."

View File

@ -1,23 +1,61 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 )"
# KubeBlocks database installation script
# Install all database clusters
# Load configuration file # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
print "Installing database clusters..." print "Installing database clusters..."
# Install database clusters based on configuration # 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_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 "$SCRIPT_DIR/redis/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 "$SCRIPT_DIR/elasticsearch/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 "$SCRIPT_DIR/qdrant/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 "$SCRIPT_DIR/mongodb/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 "$SCRIPT_DIR/neo4j/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_success "Database clusters installation completed!"
print "Use the following command to check the status of installed clusters:" print "Use the following command to check the status of installed clusters:"

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
print "Uninstalling database clusters..." print "Uninstalling database clusters..."

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
print "Uninstalling KubeBlocks database addons..." print "Uninstalling KubeBlocks database addons..."
@ -18,7 +18,7 @@ print "Uninstalling KubeBlocks database addons..."
print_success "Database addons uninstallation completed!" 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 $NAMESPACE
kubectl delete namespace kb-system kubectl delete namespace kb-system

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
# Check dependencies # Check dependencies
check_dependencies check_dependencies

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
# Get the directory where this script is located # 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 # Load configuration file
source "$SCRIPT_DIR/00-config.sh" source "$DATABASE_SCRIPT_DIR/00-config.sh"
# Check dependencies # Check dependencies
print "Checking dependencies..." print "Checking dependencies..."

View File

@ -2,27 +2,8 @@
NAMESPACE=rag NAMESPACE=rag
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 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 if [ -z "$OPENAI_API_KEY" ]; then
echo "OPENAI_API_KEY environment variable is not set" echo "OPENAI_API_KEY environment variable is not set"
read -p "Enter your OpenAI API key: " OPENAI_API_KEY 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 export OPENAI_API_BASE=$OPENAI_API_BASE
fi fi
# Check if databases are already installed, install them if not # Install KubeBlocks (if not already installed)
echo "Checking database installation status..." echo "Preparing to install KubeBlocks and required components..."
if ! kubectl get clusters -n rag pg-cluster &> /dev/null || ! kubectl get clusters -n rag neo4j-cluster &> /dev/null; then bash "$SCRIPT_DIR/databases/01-prepare.sh"
echo "Databases not installed or incompletely installed, will install required databases first..."
# Install KubeBlocks (if not already installed) # Install database clusters
echo "Preparing to install KubeBlocks and required components..." echo "Installing database clusters..."
bash "$SCRIPT_DIR/databases/01-prepare.sh" bash "$SCRIPT_DIR/databases/02-install-database.sh"
# Install database clusters # Create vector extension in PostgreSQL if enabled
echo "Installing database clusters..." if [ "$ENABLE_POSTGRESQL" = true ]; then
bash "$SCRIPT_DIR/databases/02-install-database.sh" 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
# Wait for databases to be ready print "Creating vector extension in PostgreSQL..."
echo "Waiting for databases to be ready..." 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;"
TIMEOUT=300 # Set timeout to 5 minutes print_success "Vector extension created successfully."
START_TIME=$(date +%s) else
print "Warning: PostgreSQL pods not ready within timeout. Vector extension not created."
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 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 fi
# Get database passwords from Kubernetes secrets # Get database passwords from Kubernetes secrets
@ -110,6 +56,13 @@ if [ -z "$NEO4J_PASSWORD" ]; then
fi fi
export NEO4J_PASSWORD=$NEO4J_PASSWORD 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)..." echo "Deploying production LightRAG (using external databases)..."
if ! kubectl get namespace rag &> /dev/null; then 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_MODEL=text-embedding-ada-002 \
--set-string env.EMBEDDING_DIM=1536 \ --set-string env.EMBEDDING_DIM=1536 \
--set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY --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 # Wait for LightRAG pod to be ready
echo "Waiting 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 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

View File

@ -2,7 +2,6 @@
NAMESPACE=rag NAMESPACE=rag
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
check_dependencies(){ check_dependencies(){

View File

@ -24,6 +24,15 @@ spec:
- name: http - name: http
containerPort: {{ .Values.env.PORT }} containerPort: {{ .Values.env.PORT }}
protocol: TCP protocol: TCP
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 2
successThreshold: 1
failureThreshold: 3
resources: resources:
{{- toYaml .Values.resources | nindent 12 }} {{- toYaml .Values.resources | nindent 12 }}
volumeMounts: volumeMounts:

View File

@ -38,6 +38,8 @@ env:
EMBEDDING_BINDING_API_KEY: EMBEDDING_BINDING_API_KEY:
LIGHTRAG_KV_STORAGE: PGKVStorage LIGHTRAG_KV_STORAGE: PGKVStorage
LIGHTRAG_VECTOR_STORAGE: PGVectorStorage LIGHTRAG_VECTOR_STORAGE: PGVectorStorage
# LIGHTRAG_KV_STORAGE: RedisKVStorage
# LIGHTRAG_VECTOR_STORAGE: QdrantVectorDBStorage
LIGHTRAG_GRAPH_STORAGE: Neo4JStorage LIGHTRAG_GRAPH_STORAGE: Neo4JStorage
LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage LIGHTRAG_DOC_STATUS_STORAGE: PGDocStatusStorage
# Replace with your POSTGRES credentials # Replace with your POSTGRES credentials
@ -51,3 +53,6 @@ env:
NEO4J_URI: neo4j://neo4j-cluster-neo4j:7687 NEO4J_URI: neo4j://neo4j-cluster-neo4j:7687
NEO4J_USERNAME: neo4j NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: 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