This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
install
executable file
·214 lines (185 loc) · 4.65 KB
/
install
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
#!/bin/bash
#########################################
### K3ai (keɪ3ai)
### https://github.com/kf5i/k3ai
### Alessandro Festa @bringyourownai
### Gabriele Santomaggio @gsantomaggio
#########################################
info()
{
echo '[INFO] ' "$@"
}
infoL()
{
echo -en '[INFO] ' "$@\n"
}
sleep_cursor()
{
chars="/-\|"
for (( z=0; z<7; z++ )); do
for (( i=0; i<${#chars}; i++ )); do
sleep 0.5
echo -en "${chars:$i:1}" "\r"
done
done
}
wait()
{
status=1
infoL "Testing.." $1.$2
while [ : ]
do
sleep_cursor &
k3s kubectl wait --for condition=available --timeout=14s deploy -l $1 -n $2
status=$?
if [ $status -ne 0 ]
then
infoL "$1 isn't ready yet. This may take a few minutes..."
sleep_cursor
else
break
fi
done
}
kubeflow_install_pipelines(){
manage_plugin "--plugin_kfpipelines"
}
##################
INTERNAL_INSTALL_K3S_EXEC=""
setup_env(){
# --- use sudo if we are not already root ---
SUDO=sudo
if [ $(id -u) -eq 0 ]; then
SUDO=
fi
# --- use binary install directory if defined or create default ---
if [ -n "${INSTALL_K3S_BIN_DIR}" ]; then
BIN_DIR=${INSTALL_K3S_BIN_DIR}
else
BIN_DIR=/usr/local/bin
fi
}
k3s_install_service()
{
info "Installing k3s service with the following parameters:" "${INSTALL_K3S_EXEC} ${INTERNAL_INSTALL_K3S_EXEC}"
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="${INSTALL_K3S_EXEC} ${INTERNAL_INSTALL_K3S_EXEC}" sh -s -
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
wait_k3s
}
k3s_install_service_gpu()
{
info "Installing the GPU Support on docker"
INTERNAL_INSTALL_K3S_EXEC="--docker"
k3s_install_service
#### GPU Support
k3s kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.7.0/nvidia-device-plugin.yml
}
default_installation(){
info "Installing pipelines"
k3s_install_service
kubeflow_install_pipelines
}
wait_k3s(){
info "Waiting k3s"
waiting_pod_array=("k8s-app=kube-dns;kube-system"
"k8s-app=metrics-server;kube-system"
)
for i in "${waiting_pod_array[@]}"; do
echo "$i";
IFS=';' read -ra VALUES <<< "$i"
wait "${VALUES[0]}" "${VALUES[1]}"
done
}
manage_plugin(){
PLUGIN=$1
PLUGIN="${PLUGIN:2}"
info "Installing plugin: " $PLUGIN
info "URL:" https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/v1/$PLUGIN/install
curl -sfL https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/v1/$PLUGIN/install | bash -s -
}
manage() {
### DEFAULT == --cpu and --pipelines
# if [[ "$#" -eq 0 ]]; then
# kubeflow_install_pipelines
# fi
while [[ "$#" -ne 0 ]]; do
case "$1" in
"--pipelines")
kubeflow_install_pipelines
shift 1
;;
--plugin*)
info "Installing plugin:" "$1"
manage_plugin "$1"
shift 1
;;
*)
shift 1
;;
esac
done
}
k3s_install_binary(){
info "Download the binary.."
curl -o k3s -sfL https://github.com/rancher/k3s/releases/download/v1.19.2%2Bk3s1/k3s
chmod +x k3s
info "Install the binary to: " $BIN_DIR
$SUDO mv k3s $BIN_DIR
curl -o startk3s -sfL https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/v1/plugin_wsl_start/startk3s
$SUDO mv startk3s $BIN_DIR
chmod +x $BIN_DIR/startk3s
info "Starting k3s in detached mode"
startk3s
info "Waiting..."
sleep_cursor
sleep 2
wait_k3s
}
MESSAGE="k3s-uninstall.sh to uninstall"
main() {
setup_env
### DEFAULT == --cpu and --pipelines
if [[ "$#" -eq 0 ]]; then
default_installation
fi
OR="$@"
while [[ "$#" -ne 0 ]]; do
case "$1" in
"--gpu")
k3s_install_service_gpu
manage $OR
shift 1
;;
"--cpu")
info "Installing the CPU Support"
k3s_install_service
manage $OR
shift 1
;;
"--wsl")
info "Installing the wsl Support"
MESSAGE="Use the command stark3s to restart the server"
MESSAGE="$MESSAGE You can put it un autostart configuration to restart it automatically"
k3s_install_binary
manage $OR
shift 1
;;
"--skipk3s")
info "Skip Installation Server"
manage $OR
shift 1
;;
*)
shift 1
;;
esac
done
}
if [[ "${OSTYPE/-*}" != "linux" ]]; then
info "K3ai works only on Linux. The new version: https://github.com/kf5i/k3ai-core will be cross-platform :)!"
else
main "$@"
info "K3ai setup finished"
info $MESSAGE
info "Check the nodes status using: k3s kubectl get node"
fi