-
Notifications
You must be signed in to change notification settings - Fork 3
/
02_create_bootstrap_cluster.sh
executable file
·65 lines (50 loc) · 1.68 KB
/
02_create_bootstrap_cluster.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
#!/bin/bash
set -e
source lib/common.sh
if [ -z "$1" ]; then
echo "usage: $0 <assets dir>"
exit 1
fi
ASSETS_DIR=$1
KIND_ASSETS_DIR="$1/kind/$(ls $1/kind | grep v)"
check_if_supported_os
GUM_ASSETS_DIR="$ASSETS_DIR/gum/$(ls $ASSETS_DIR/gum | grep v)"
sudo cp $GUM_ASSETS_DIR/gum_*/gum /usr/local/bin
# TODO: check if the bootstrap cluster already exist.
rm -rf ~/.kube/config
check_if_supported_os
log_info "Installing Docker-ce"
# TODO: install only when not installed
case $OS_ID in
"rocky" | "centos" | "rhel")
sudo dnf localinstall $ASSETS_DIR/docker-ce/*.rpm
;;
"ubuntu" )
sudo dpkg -i $ASSETS_DIR/docker-ce/*.deb
;;
esac
sudo systemctl start docker
sudo docker load -i $ASSETS_DIR/kind-node-image.tar.gz
log_info "Creating bootstrap cluster"
sudo cp $ASSETS_DIR/kubectl /usr/local/bin
sudo chmod +x /usr/local/bin/kubectl
sudo cp $KIND_ASSETS_DIR/kind-linux-amd64 /usr/local/bin/kind
sudo chmod +x /usr/local/bin/kind
sudo cp $1/helm /usr/local/bin
export BOOTSTRAP_CLUSTER_SERVER_IP
envsubst '${BOOTSTRAP_CLUSTER_SERVER_IP}' < ./templates/kind-config.yaml.template >output/kind-config.yaml
sudo /usr/local/bin/kind create cluster --config=output/kind-config.yaml --image kindest/node:$KIND_NODE_IMAGE_TAG
mkdir -p ~/.kube
sudo cp /root/.kube/config ~/.kube
sudo chown $USER:$USER ~/.kube/config
sed -i "s/0.0.0.0:6443/$BOOTSTRAP_CLUSTER_SERVER_IP:6443/g" ~/.kube/config
while true
do
node_status=$(kubectl get no -o=jsonpath='{.items[0].status.conditions[?(@.type == "Ready")].status}')
if [ $node_status = "True" ]
then
break
fi
sleep 10
done
log_info "Bootstrap cluster created successfully. You can access bootstrap cluster using ~/.kube/config as a kubeconfig file"