-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·374 lines (347 loc) · 12.5 KB
/
install.sh
File metadata and controls
executable file
·374 lines (347 loc) · 12.5 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/env bash
set -eo pipefail
shopt -s expand_aliases
# initArch discovers the architecture for this system.
init_arch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}
function clean_before_exit {
# delay before exiting, so stdout/stderr flushes through the logging system
rm -rf /tmp/drycc-values.yaml /etc/rancher/k3s/registries.yaml
configure_registries runtime
systemctl restart k3s
sleep 3
}
trap clean_before_exit EXIT
init_arch
function install_helm {
tar_name="helm-canary-linux-${ARCH}.tar.gz"
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
helm_download_url="https://github.com/helm/${tar_name}"
else
helm_download_url="https://get.helm.sh/${tar_name}"
fi
curl -fsSL -o "${tar_name}" "${helm_download_url}"
tar -zxvf "${tar_name}"
mv "linux-${ARCH}/helm" /usr/local/bin/helm
rm -rf "${tar_name}" "linux-${ARCH}"
helm repo add drycc https://charts.drycc.cc/${CHANNEL:-stable}
}
function configure_os {
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -P FORWARD ACCEPT
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
mount bpffs -t bpf /sys/fs/bpf
}
function configure_registries {
mkdir -p /etc/rancher/k3s
if [[ "$1" == "runtime" ]] ; then
if [[ -f "${REGISTRIES_FILE}" ]] ; then
cat "${REGISTRIES_FILE}" > /etc/rancher/k3s/registries.yaml
elif [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
cat << EOF > "/etc/rancher/k3s/registries.yaml"
mirrors:
"docker.io":
endpoint:
- "https://hub-mirror.c.163.com"
- "https://registry-1.docker.io"
EOF
fi
else
cat << EOF > "/etc/rancher/k3s/registries.yaml"
mirrors:
"docker.io":
endpoint:
- "https://gcr-mirror.drycc.cc"
- "https://registry-1.docker.io"
"quay.io":
endpoint:
- "https://quay-mirror.drycc.cc"
- "https://quay.io"
"gcr.io":
endpoint:
- "https://gcr-mirror.drycc.cc"
- "https://gcr.io"
"k8s.gcr.io":
endpoint:
- "https://k8s-mirror.drycc.cc"
- "https://k8s.gcr.io"
EOF
fi
}
function configure_mirrors {
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
configure_registries
INSTALL_K3S_MIRROR="${INSTALL_DRYCC_MIRROR}"
export INSTALL_K3S_MIRROR
k3s_install_url="http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh"
else
k3s_install_url="https://get.k3s.io"
fi
}
function install_cin_plugins {
mkdir -p /opt/cni/bin
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
cni_plugins_url="https://github.com/cni/plugins/releases"
else
cni_plugins_url="https://github.com/containernetworking/plugins/releases"
fi
version=$(curl -Ls ${cni_plugins_url}|grep /containernetworking/plugins/releases/tag/ | grep -v no-underline | head -n 1 | cut -d '"' -f 2| awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}')
tar_name="cni-plugins-linux-${ARCH}-$version.tgz"
download_url="${cni_plugins_url}/download/${version}/${tar_name}"
curl -fsSL -o "${tar_name}" "${download_url}"
tar -zxvf "${tar_name}" -C /opt/cni/bin
rm -rf "${tar_name}"
}
function install_k3s_server {
configure_os
configure_mirrors
install_cin_plugins
INSTALL_K3S_EXEC="server ${INSTALL_K3S_EXEC} --flannel-backend=none --disable=traefik --disable=local-storage --disable=servicelb --cluster-cidr=10.233.0.0/16"
if [[ -n "${K3S_DATA_DIR}" ]] ; then
INSTALL_K3S_EXEC="$INSTALL_K3S_EXEC --data-dir=${K3S_DATA_DIR}/rancher/k3s"
fi
if [[ -z "${K3S_URL}" ]] ; then
INSTALL_K3S_EXEC="$INSTALL_K3S_EXEC --cluster-init"
fi
curl -sfL "${k3s_install_url}" |INSTALL_K3S_EXEC="$INSTALL_K3S_EXEC" sh -s -
}
function install_k3s_agent {
configure_os
configure_mirrors
install_cin_plugins
if [[ -n "${K3S_DATA_DIR}" ]] ; then
INSTALL_K3S_EXEC="$INSTALL_K3S_EXEC --data-dir=${K3S_DATA_DIR}/rancher/k3s"
fi
curl -sfL "${k3s_install_url}" |INSTALL_K3S_EXEC="$INSTALL_K3S_EXEC" sh -s -
}
function install_components {
helm repo update
echo -e "\\033[32m---> Waiting for helm to install components...\\033[0m"
helm install cilium drycc/cilium --set operator.replicas=1 --set cni.chainingMode=portmap --namespace kube-system --wait
helm install metallb drycc/metallb --namespace kube-system --wait -f - <<EOF
configInline:
address-pools:
- name: default
protocol: layer2
addresses:
- ${METALLB_ADDRESS_POOLS:-172.16.0.0/12}
EOF
helm install ingress-nginx drycc/ingress-nginx --namespace kube-system --wait
helm install cert-manager drycc/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true --wait
# Use arm64 and amd64 arch of docker.io/drycc/service-catalog:canary, it will be deleted in the future.
helm install catalog drycc/catalog \
--set asyncBindingOperationsEnabled=true \
--set image=docker.io/drycc/service-catalog:canary \
--namespace catalog \
--create-namespace --wait
}
function install_longhorn {
if [[ -n "${LONGHORN_DATA_PATH}" ]] ; then
LONGHORN_DATA_PATH="${LONGHORN_DATA_PATH}/longhorn"
fi
helm install longhorn drycc/longhorn --create-namespace \
--set persistence.defaultClass=true \
--set persistence.defaultClassReplicaCount=1 \
--set defaultSettings.defaultDataPath=${LONGHORN_DATA_PATH:-""} \
--namespace longhorn-system --wait
}
function check_drycc_env {
if [[ -z "${PLATFORM_DOMAIN}" ]] ; then
echo -e "\\033[31m---> Please set the PLATFORM_DOMAIN variable.\\033[0m"
echo -e "\\033[31m---> For example:\\033[0m"
echo -e "\\033[31m---> export PLATFORM_DOMAIN=drycc.cc\\033[0m"
echo -e "\\033[31m---> And confirm that wildcard domain name resolution has been set.\\033[0m"
echo -e "\\033[31m---> For example, the current server IP is 8.8.8.8\\033[0m"
echo -e "\\033[31m---> Please point *.drycc.cc to 8.8.8.8\\033[0m"
exit 1
fi
if [[ -z "${DRYCC_ADMIN_USERNAME}" || -z "${DRYCC_ADMIN_PASSWORD}" ]] ; then
echo -e "\\033[31m---> Please set the DRYCC_ADMIN_USERNAME and DRYCC_ADMIN_PASSWORD variable.\\033[0m"
echo -e "\\033[31m---> For example:\\033[0m"
echo -e "\\033[31m---> export DRYCC_ADMIN_USERNAME=admin\\033[0m"
echo -e "\\033[31m---> export DRYCC_ADMIN_PASSWORD=admin\\033[0m"
echo -e "\\033[31m---> This password is used by end users to log in and manage drycc.\\033[0m"
echo -e "\\033[31m---> Please set a high security string!!!\\033[0m"
exit 1
fi
}
function install_drycc {
check_drycc_env
echo -e "\\033[32m---> Start installing workflow...\\033[0m"
RABBITMQ_USERNAME=$(cat /proc/sys/kernel/random/uuid)
RABBITMQ_PASSWORD=$(cat /proc/sys/kernel/random/uuid)
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
cat << EOF > "/tmp/drycc-values.yaml"
imagebuilder:
container_registries: |
unqualified-search-registries = ["docker.io"]
short-name-mode="permissive"
[[registry]]
prefix = "docker.io"
location = "registry-1.docker.io"
[[registry.mirror]]
prefix = "docker.io"
location = "hub-mirror.c.163.com"
EOF
else
cat << EOF > "/tmp/drycc-values.yaml"
imagebuilder:
container_registries: |
unqualified-search-registries = ["docker.io"]
short-name-mode="permissive"
EOF
fi
helm install drycc drycc/workflow \
--set builder.service.type=LoadBalancer \
--set global.cluster_domain="cluster.local" \
--set global.platform_domain="${PLATFORM_DOMAIN}" \
--set global.cert_manager_enabled=${CERT_MANAGER_ENABLED:-true} \
--set global.ingress_class=nginx \
--set fluentd.daemon_environment.CONTAINER_TAIL_PARSER_TYPE="/^(?<time>.+) (?<stream>stdout|stderr)( (?<tags>.))? (?<log>.*)$/" \
--set controller.app_storage_class=${CONTROLLER_APP_STORAGE_CLASS:-""} \
--set minio.persistence.enabled=true \
--set minio.persistence.size=${MINIO_PERSISTENCE_SIZE:-20Gi} \
--set minio.persistence.storageClass=${MINIO_PERSISTENCE_STORAGE_CLASS:-""} \
--set rabbitmq.username="${RABBITMQ_USERNAME}" \
--set rabbitmq.password="${RABBITMQ_PASSWORD}" \
--set rabbitmq.persistence.enabled=true \
--set rabbitmq.persistence.size=${RABBITMQ_PERSISTENCE_SIZE:-5Gi} \
--set rabbitmq.persistence.storageClass=${RABBITMQ_PERSISTENCE_STORAGE_CLASS:-""} \
--set influxdb.persistence.enabled=true \
--set influxdb.persistence.size=${INFLUXDB_PERSISTENCE_SIZE:-5Gi} \
--set influxdb.persistence.storageClass=${INFLUXDB_PERSISTENCE_STORAGE_CLASS:-""} \
--set monitor.grafana.persistence.enabled=true \
--set monitor.grafana.persistence.size=${MONITOR_GRAFANA_PERSISTENCE_SIZE:-5Gi} \
--set monitor.grafana.storageClass=${MONITOR_GRAFANA_PERSISTENCE_STORAGE_CLASS:-""} \
--set passport.admin_username=${DRYCC_ADMIN_USERNAME} \
--set passport.admin_password=${DRYCC_ADMIN_PASSWORD} \
--namespace drycc \
--values /tmp/drycc-values.yaml \
--create-namespace --wait --timeout 30m0s
echo -e "\\033[32m---> Rabbitmq username: $RABBITMQ_USERNAME\\033[0m"
echo -e "\\033[32m---> Rabbitmq password: $RABBITMQ_PASSWORD\\033[0m"
}
function install_helmbroker {
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
addons_url="https://github.com/drycc/addons/releases/download/latest/index.yaml"
else
addons_url="https://github.com/drycc/addons/releases/download/latest/index.yaml"
fi
HELMBROKER_USERNAME=$(cat /proc/sys/kernel/random/uuid)
HELMBROKER_PASSWORD=$(cat /proc/sys/kernel/random/uuid)
echo -e "\\033[32m---> Start installing helmbroker...\\033[0m"
helm install helmbroker drycc/helmbroker \
--set ingress_class="nginx" \
--set platform_domain="cluster.local" \
--set persistence.size=${HELMBROKER_PERSISTENCE_SIZE:-5Gi} \
--set persistence.storageClass=${HELMBROKER_PERSISTENCE_STORAGE_CLASS:=""} \
--set platform_domain=${PLATFORM_DOMAIN} \
--set cert_manager_enabled=${CERT_MANAGER_ENABLED:-true} \
--set username=${HELMBROKER_USERNAME} \
--set password=${HELMBROKER_PASSWORD} \
--set environment.HELMBROKER_CELERY_BROKER="amqp://${RABBITMQ_USERNAME}:${RABBITMQ_PASSWORD}@drycc-rabbitmq-0.drycc-rabbitmq.drycc.svc.cluster.local:5672/drycc" \
--namespace drycc --create-namespace --wait -f - <<EOF
repositories:
- name: drycc-helm-broker
url: ${addons_url}
EOF
if [[ "${CERT_MANAGER_ENABLED:-true}" == "true" ]] ; then
BROKER_URL="https://${HELMBROKER_USERNAME}:${HELMBROKER_PASSWORD}@drycc-helmbroker.${PLATFORM_DOMAIN}"
else
BROKER_URL="http://${HELMBROKER_USERNAME}:${HELMBROKER_PASSWORD}@drycc-helmbroker.${PLATFORM_DOMAIN}"
fi
kubectl apply -f - <<EOF
apiVersion: servicecatalog.k8s.io/v1beta1
kind: ClusterServiceBroker
metadata:
finalizers:
- kubernetes-incubator/service-catalog
generation: 1
labels:
app.kubernetes.io/managed-by: Helm
heritage: Helm
name: helmbroker
spec:
relistBehavior: Duration
relistRequests: 5
url: ${BROKER_URL}
EOF
echo -e "\\033[32m---> Helmbroker username: $HELMBROKER_USERNAME\\033[0m"
echo -e "\\033[32m---> Helmbroker password: $HELMBROKER_PASSWORD\\033[0m"
}
function configure_haproxy {
BUILDER_IP=$(kubectl get svc drycc-builder -n drycc -o="jsonpath={.status.loadBalancer.ingress[0].ip}")
INGRESS_IP=$(kubectl get svc ingress-nginx-controller -n kube-system -o="jsonpath={.status.loadBalancer.ingress[0].ip}")
if [[ "${USE_HAPROXY:-true}" == "true" ]] ; then
cat << EOF > "/etc/haproxy/haproxy.cfg"
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
listen http-80
bind *:80
mode tcp
maxconn 100000
timeout connect 60s
timeout client 30000
timeout server 30000
server ingress ${INGRESS_IP}:80 check
listen https-443
bind *:443
mode tcp
maxconn 100000
timeout connect 60s
timeout client 30000
timeout server 30000
server ingress ${INGRESS_IP}:443 check
listen builder
bind *:2222
mode tcp
maxconn 100000
timeout connect 60s
timeout client 30000
timeout server 30000
server builder ${BUILDER_IP}:2222 check
EOF
fi
mkdir -p /run/haproxy
systemctl enable haproxy
systemctl restart haproxy
}
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
if [[ -z "$@" ]] ; then
install_k3s_server
install_helm
install_components
install_longhorn
install_drycc
configure_haproxy
install_helmbroker
echo -e "\\033[32m---> Installation complete, enjoy life...\\033[0m"
else
for command in "$@"
do
$command
echo -e "\\033[32m---> Execute $command complete, enjoy life...\\033[0m"
done
fi