-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap_k8s.sh
executable file
·66 lines (55 loc) · 1.71 KB
/
bootstrap_k8s.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
#!/usr/bin/env bash
set -e
set -x
if [ -f /tmp/bootstrap.done ] ; then
echo "Kubernetes is already installed, skipping install step"
exit 0
fi
if [ -z $K8S_VERSION ] ; then
echo "Please set K8S_VERSION variable"
exit 1
fi
if [ -z $NUM_NODES ] ; then
echo "Please set NUM_NODES variable"
exit 1
elif [ $NUM_NODES -lt 1 ]; then
echo "NUM_NODES variable value should be at least equal to 1"
exit 1
fi
if [ $(kind get clusters | grep -c kind) == 1 ] ; then
echo "Kubernetes is already installed, skipping install"
exit 0
fi
# Load env vars
source $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/env.bash
# Download and run k8s
echo "Downloading Kind and kubectl"
curl -sLo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64
curl -sLo ./kubectl https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl
chmod +x ./kind ./kubectl
mv kind kubectl /usr/bin/
echo "Generating kind config"
echo 'kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane' > kind.config
for i in `seq 1 $NUM_NODES`; do
echo '- role: worker' >> kind.config
done
echo "Launching Kubernetes install"
kind create cluster --config kind.config --image kindest/node:v${K8S_VERSION}
if [ $? == 0 ] ; then
touch /tmp/bootstrap.done
rm -f kind.config
else
echo "Error during Kubernetes bootstrap"
exit 1
fi
echo "Set this cluster as default one"
if [ ! -f ~/.kube/config ] ; then
cp $(kind get kubeconfig-path --name="kind") ~/.kube/config
else
echo "Can't copy kube config to default location because you already have one"
fi
echo "Setup bashrc for kubectl and helm"
echo PATH="$PATH" >> ~/.bashrc