-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·277 lines (233 loc) · 7.78 KB
/
setup.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#! /bin/bash
install_environment()
{
echo ""
echo -e "\033[1mInstall environment...\033[0m"
echo ""
echo -e "\033[1mInstall docker...\033[0m"
curl -fsSL https://get.docker.com -o get-docker.sh && \
sudo sh get-docker.sh && \
rm get-docker.sh && \
echo "" && \
echo -e "\033[1mInstall minikube and kubectl...\033[0m" && \
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && \
sudo install minikube-linux-amd64 /usr/local/bin/minikube && \
curl -LO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl && \
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm -rf minikube-linux-amd64 kubectl
if [ $? -ne 0 ]; then
echo ""
echo "Error"
exit
else
echo ""
echo "Packages installed!"
echo "Now you can run"
echo -e "\033[1m$ bash setup.sh\033[0m"
fi
}
start_environment()
{
echo ""
echo -e "\033[1mStart minikube...\033[0m"
sudo systemctl restart docker && \
sudo chown $USER /var/run/docker.sock && \
minikube --cpus=2 --memory=2500 start --driver=docker && \
minikube addons enable storage-provisioner && \
minikube addons enable metrics-server && \
minikube addons enable dashboard && \
minikube addons enable ingress
if [ $? -ne 0 ]; then
echo "Error"
exit
fi
}
delete_environment()
{
echo ""
echo -e "\033[1mDelete minikube...\033[0m"
minikube delete
sudo pkill nginx
rm -rf ~/.kube
}
uninstall_environment()
{
echo ""
echo -e "\033[1mUninstall environment...\033[0m"
echo ""
echo -e "\033[1mUninstall minikube and kubectl...\033[0m"
minikube delete
sudo rm -rf \
/usr/local/bin/minikube \
/usr/local/bin/kubectl \
~/.kube \
~/.minikube
echo ""
echo -e "\033[1mUninstall docker...\033[0m"
sudo apt-get autoremove -y --purge docker-engine docker
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
}
apply_config()
{
echo ""
echo -e "\033[1mApply configuration files...\033[0m"
kubectl apply -f srcs/k8s/metallb.yaml && \
kubectl apply -f srcs/k8s/nginx.yaml && \
kubectl apply -f srcs/k8s/ftps.yaml && \
kubectl apply -f srcs/k8s/mysql.yaml && \
kubectl apply -f srcs/k8s/phpmyadmin.yaml && \
kubectl apply -f srcs/k8s/wordpress.yaml && \
kubectl apply -f srcs/k8s/grafana.yaml && \
kubectl apply -f srcs/k8s/influxdb.yaml
if [ $? -ne 0 ]; then
echo "Error"
exit
fi
}
clean_config()
{
echo ""
echo -e "\033[1mClean configuration files...\033[0m"
kubectl delete -f srcs/k8s/metallb.yaml
kubectl delete -f srcs/k8s/nginx.yaml
kubectl delete -f srcs/k8s/ftps.yaml
kubectl delete -f srcs/k8s/mysql.yaml
kubectl delete -f srcs/k8s/phpmyadmin.yaml
kubectl delete -f srcs/k8s/wordpress.yaml
kubectl delete -f srcs/k8s/grafana.yaml
kubectl delete -f srcs/k8s/influxdb.yaml
}
build_images()
{
echo ""
echo -e "\033[1mBuild images...\033[0m"
echo -n "Nginx image " && \
docker build srcs/nginx -t nginx:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "FTPS image " && \
docker build srcs/ftps -t ftps:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "MySQL image " && \
docker build srcs/mysql -t mysql:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "PhpMyAdmin image " && \
docker build srcs/phpmyadmin -t phpmyadmin:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "Wordpress image " && \
docker build srcs/wordpress -t wordpress:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "Grafana image " && \
docker build srcs/grafana -t grafana:vscabell >> log_setup.txt && \
echo "created" && \
echo -n "InfluxDB image " && \
docker build srcs/influxdb -t influxdb:vscabell >> log_setup.txt
echo "created"
if [ $? -ne 0 ]; then
echo ""
echo "Error"
exit
fi
}
clean_images()
{
echo ""
echo -e "\033[1mClean images...\033[0m"
docker stop $(docker ps -aq --filter name=k8s)
docker rm $(docker ps -aq --filter name=k8s)
docker rmi -f nginx:vscabell
docker rmi -f ftps:vscabell
docker rmi -f mysql:vscabell
docker rmi -f phpmyadmin:vscabell
docker rmi -f wordpress:vscabell
docker rmi -f grafana:vscabell
docker rmi -f influxdb:vscabell
}
install_metallb()
{
echo ""
echo -e "\033[1mInstall metallb...\033[0m"
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml && \
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml && \
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)" && \
minikube addons enable metallb
if [ $? -ne 0 ]; then
echo "Error"
exit
fi
}
atribute_ip()
{
echo ""
echo -e "\033[1mAtribute IP...\033[0m"
MINIKUBEIP=$(minikube ip) && \
IP=${MINIKUBEIP::-1}"$((${MINIKUBEIP: -1} + 1))" && \
sed -i "s/FIRSTIP-LASTIP/$IP-$IP/g" ./srcs/k8s/metallb.yaml && \
sed -i "s/IP/$IP/g" ./srcs/ftps/srcs/vsftpd.conf && \
sed -i "s/CLUSTER_IP/$IP/g" ./srcs/mysql/srcs/wordpress.sql && \
sed -i "s/IP/$IP/g" ./srcs/nginx/srcs/index.html
if [ $? -ne 0 ]; then
echo "Error"
exit
fi
}
show_services()
{
echo ""
echo -e "\033[1mOpening kubernetes web dashboard ...\033[0m"
minikube dashboard &> /dev/null &
MINIKUBEIP=$(minikube ip)
IP=${MINIKUBEIP::-1}"$((${MINIKUBEIP: -1} + 1))"
echo -e ""
echo -e "\033[1m ~> Available Services \033[0m"
echo -e " _____________________________________________________________"
echo -e "| | | | |"
echo -e "| SERVICE | USER | PASSWORD | URL |"
echo -e "|____________|_________|__________|___________________________|"
echo -e "| | | | |"
echo -e "| NGINX | | | http://$IP:80 |"
echo -e "| | | | https://$IP:443 |"
echo -e "| | | | |"
echo -e "| WORDPRESS | admin | admin | https://$IP:5050 |"
echo -e "| | user1 | user1 | |"
echo -e "| | user2 | user2 | |"
echo -e "| | user3 | user3 | |"
echo -e "| | | | |"
echo -e "| PHPMYADMIN | admin | admin | https://$IP:5000 |"
echo -e "| | | | |"
echo -e "| GRAFANA | admin | admin | http://$IP:3000 |"
echo -e "| | | | |"
echo -e "| FTPS | admin | admin | ftp://$IP:21 |"
echo -e "|____________|_________|__________|___________________________|"
echo -e ""
}
########## FT SERVICES ##########
echo "" > log_setup.txt
if [ "$1" == "apply" ]; then
clean_config
eval $(minikube docker-env)
clean_images
atribute_ip
build_images
apply_config
elif [ "$1" == "config" ]; then
kubectl delete -f srcs/k8s --recursive
kubectl apply -f srcs/k8s --recursive
elif [ "$1" == "show" ]; then
show_services
elif [ "$1" == "del" ]; then
delete_environment
elif [ "$1" == "install" ]; then
install_environment
elif [ "$1" == "uninstall" ]; then
uninstall_environment
else
delete_environment
start_environment
eval $(minikube docker-env)
install_metallb
atribute_ip
build_images
apply_config
show_services
fi