From c5320afbfdaa8119bb0a1e234bf323ede3c1f773 Mon Sep 17 00:00:00 2001 From: Mostafa Kamal Date: Sat, 16 Nov 2024 15:11:49 +0600 Subject: [PATCH] update doc and bash --- README.md | 8 ++++++ install.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fafe936..31e1853 100644 --- a/README.md +++ b/README.md @@ -79,3 +79,11 @@ $ kubectl get secrets --namespace=logging elasticsearch-master-credentials -ojso ``` * `username is elastic` + +# sample project deploy + +```bash +kubectl create namespace backend +kubectl apply -f project.yml +``` + diff --git a/install.sh b/install.sh index 2f4acf9..e90c1a2 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,8 @@ show_menu() { echo "2. Install Kibana" echo "3. Install Fluent Bit" echo "4. Install Complete Stack" - echo "5. Exit" + echo "5. Uninstall Complete Stack" + echo "6. Exit" } # Setup namespace @@ -51,28 +52,45 @@ setup_helm_repo_fluentbit() { # Install components install_elasticsearch() { - echo "Installing Elasticsearch..." - helm install elasticsearch elastic/elasticsearch -f ek/elasticsearch-values.yaml -n logging || { echo "Failed to install Elasticsearch"; exit 1; } + echo "Checking Elasticsearch installation..." + if helm list -n logging | grep -q "elasticsearch"; then + echo "Elasticsearch already exists, upgrading..." + helm upgrade elasticsearch elastic/elasticsearch -f ek/elasticsearch-values.yaml -n logging || { echo "Failed to upgrade Elasticsearch"; exit 1; } + else + echo "Installing Elasticsearch..." + helm install elasticsearch elastic/elasticsearch -f ek/elasticsearch-values.yaml -n logging || { echo "Failed to install Elasticsearch"; exit 1; } + fi } install_kibana() { - echo "Installing Kibana..." - helm install kibana elastic/kibana -f ek/kibana-values.yaml -n logging || { echo "Failed to install Kibana"; exit 1; } + echo "Checking Kibana installation..." + if helm list -n logging | grep -q "kibana"; then + echo "Kibana already exists, upgrading..." + helm upgrade kibana elastic/kibana -f ek/kibana-values.yaml -n logging || { echo "Failed to upgrade Kibana"; exit 1; } + else + echo "Installing Kibana..." + helm install kibana elastic/kibana -f ek/kibana-values.yaml -n logging || { echo "Failed to install Kibana"; exit 1; } + fi } install_fluentbit() { - echo "Installing Fluent Bit..." - helm install fluentbit fluent/fluent-bit -f fluentbit/values.yaml -n logging || { echo "Failed to install Fluent Bit"; exit 1; } + echo "Checking Fluent Bit installation..." + if helm list -n logging | grep -q "fluentbit"; then + echo "Fluent Bit already exists, upgrading..." + helm upgrade fluentbit fluent/fluent-bit -f fluentbit/values.yaml -n logging || { echo "Failed to upgrade Fluent Bit"; exit 1; } + else + echo "Installing Fluent Bit..." + helm install fluentbit fluent/fluent-bit -f fluentbit/values.yaml -n logging || { echo "Failed to install Fluent Bit"; exit 1; } + fi } # Add sleep function with loading animation wait_with_loader() { local seconds=$1 - local message="Please wait while the system initializes" + local message="${2:-Please wait while the system initializes}" local spin='-\|/' local i=0 - echo "Quote: $(get_random_quote)" for ((s=seconds; s>0; s--)); do i=$(( (i+1) %4 )) printf "\r${message} ${spin:$i:1} (${s}s remaining)" @@ -81,12 +99,39 @@ wait_with_loader() { printf "\r${message} Done!\n" } +# Add new uninstall function +uninstall_stack() { + echo "Uninstalling EFK Stack..." + + # Uninstall Fluent Bit + if helm list -n logging | grep -q "fluentbit"; then + echo "Uninstalling Fluent Bit..." + helm uninstall fluentbit -n logging || echo "Failed to uninstall Fluent Bit" + fi + + # Uninstall Kibana + if helm list -n logging | grep -q "kibana"; then + echo "Uninstalling Kibana..." + helm uninstall kibana -n logging || echo "Failed to uninstall Kibana" + fi + + # Uninstall Elasticsearch + if helm list -n logging | grep -q "elasticsearch"; then + echo "Uninstalling Elasticsearch..." + helm uninstall elasticsearch -n logging || echo "Failed to uninstall Elasticsearch" + fi + + # Delete namespace + echo "Deleting logging namespace..." + kubectl delete namespace logging --timeout=60s || echo "Failed to delete namespace" +} + # Main execution main() { print_banner show_menu - read -p "Enter your choice (1-5): " choice + read -p "Enter your choice (1-6): " choice case $choice in 1) @@ -110,19 +155,22 @@ main() { setup_helm_repo_fluentbit install_elasticsearch - wait_with_loader 110 + wait_with_loader 110 "Waiting for Elasticsearch to be ready ..." install_kibana - wait_with_loader 110 + wait_with_loader 110 "Waiting for Kibana to be ready ..." install_fluentbit ;; 5) + uninstall_stack + ;; + 6) echo "Exiting..." exit 0 ;; *) - echo "Invalid option. Please select 1-5." + echo "Invalid option. Please select 1-6." exit 1 ;; esac