-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·181 lines (158 loc) · 5.46 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# Print banner
print_banner() {
echo "----------------------------------------"
echo "EFK Stack Installation Script"
echo "Elasticsearch + Fluent Bit + Kibana"
echo "----------------------------------------"
}
# Display menu options
show_menu() {
echo "Please select an option:"
echo "1. Install Elasticsearch"
echo "2. Install Kibana"
echo "3. Install Fluent Bit"
echo "4. Install Complete Stack"
echo "5. Uninstall Complete Stack"
echo "6. Exit"
}
# Setup namespace
setup_namespace() {
if ! kubectl get namespace | grep -q "logging"; then
echo "Creating 'logging' namespace..."
kubectl create namespace logging || { echo "Failed to create namespace"; exit 1; }
else
echo "The 'logging' namespace already exists."
fi
}
# Setup Helm repo
setup_helm_repo_elastic() {
if ! helm repo list | grep -q "https://helm.elastic.co"; then
echo "Adding Elastic Helm repo..."
helm repo add elastic https://helm.elastic.co || { echo "Failed to add Helm repo"; exit 1; }
else
echo "Elastic Helm repo is already added."
fi
echo "Updating Helm repositories..."
helm repo update
}
setup_helm_repo_fluentbit() {
if ! helm repo list | grep -q "https://fluent.github.io/helm-charts"; then
echo "Adding Fluent Bit Helm repo..."
helm repo add fluent https://fluent.github.io/helm-charts || { echo "Failed to add Helm repo"; exit 1; }
else
echo "Fluent Bit Helm repo is already added."
fi
}
# Install components
install_elasticsearch() {
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 "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 "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="${2:-Please wait while the system initializes}"
local spin='-\|/'
local i=0
for ((s=seconds; s>0; s--)); do
i=$(( (i+1) %4 ))
printf "\r${message} ${spin:$i:1} (${s}s remaining)"
sleep 1
done
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-6): " choice
case $choice in
1)
setup_namespace
setup_helm_repo_elastic
install_elasticsearch
;;
2)
setup_namespace
setup_helm_repo_elastic
install_kibana
;;
3)
setup_namespace
setup_helm_repo_fluentbit
install_fluentbit
;;
4)
setup_namespace
setup_helm_repo_elastic
setup_helm_repo_fluentbit
install_elasticsearch
wait_with_loader 110 "Waiting for Elasticsearch to be ready ..."
install_kibana
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-6."
exit 1
;;
esac
echo "Operation completed!"
}
main