-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·73 lines (57 loc) · 2.32 KB
/
start.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
#!/usr/bin/env bash
set -e
# This file will invoke scripts that will create the cluster; before doing
# that, YAML files will be edited accorded to components you wish to install;
# such components will be discovered after parsing config file.
if ! [[ -f ./config ]]; then
echo "config file does not exist. Quitting"
exit 1
fi
# Exporting variables in config files so that they can be seen in
# other scripts
while read -r line; do
[[ -n "$line" ]] && export "$line" && echo "export $line"
done < config
host_http_port=9080
host_https_port=9443
# Create as many kind:Cluster files as required from NUM_CLUSTERS
for ((cluster = 0; cluster < NUM_CLUSTERS; cluster++)); do
# Copy kind:Cluster template
cp ./manifests/cluster/create-cluster.yaml.template \
./manifests/cluster/create-cluster-$cluster.yaml
# Rename current cluster
yq ".name = \"mylab-$cluster\"" \
-i manifests/cluster/create-cluster-$cluster.yaml
# Add (extra) master nodes
for ((master = 0; master < EXTRA_MASTERS; master++)); do
yq ".nodes += [{\"role\": \"control-plane\"}]" \
-i manifests/cluster/create-cluster-$cluster.yaml
done
# Add worker nodes
for ((worker = 0; worker < NUM_WORKERS; worker++)); do
yq ".nodes += [{\"role\": \"worker\"}]" \
-i manifests/cluster/create-cluster-$cluster.yaml
done
# nginx
# https://kind.sigs.k8s.io/docs/user/ingress/#create-cluster
if [[ $NGINX == true ]]; then
yq '.nodes[0] += {
"kubeadmConfigPatches": [
"kind: InitConfiguration\nnodeRegistration:\n kubeletExtraArgs:\n node-labels: \"ingress-ready=true\""
],
"extraPortMappings": [
{"containerPort": 80, "hostPort": 80, "protocol": "TCP"},
{"containerPort": 443, "hostPort": 443, "protocol": "TCP"}
]
}' -i manifests/cluster/create-cluster-$cluster.yaml
sed -i "s/hostPort: 80/hostPort: ${host_http_port}/" \
manifests/cluster/create-cluster-$cluster.yaml
sed -i "s/hostPort: 443/hostPort: ${host_https_port}/" \
manifests/cluster/create-cluster-$cluster.yaml
host_http_port=$((host_http_port+1))
host_https_port=$((host_https_port+1))
fi
done
./scripts/create-cluster.sh && \
sleep 5 && \
./scripts/setup-cluster.sh