-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker_init.sh
58 lines (53 loc) · 1.43 KB
/
worker_init.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
RED='\033[0;31m'
NC='\033[0m' # No Color
for arg in "$@"
do
case $arg in
-i | --ip)
ip=$2
shift
shift
;;
-t | --token)
token=$2
shift
shift
;;
-ca | --ca-certificate)
ca=$2
shift
shift
;;
-h|--help)
cat help_worker.txt
exit 1
;;
-*|--*)
echo "Unknown argument $1"
cat help_worker.txt
exit 1
;;
esac
done
if [[ $ip != "" && $token!="" && $ca!="" ]]
then
# Setup configuration
printf "${RED}Step 1/3: Setup installation ${NC}\n"
apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
# Install kubelet kubeadm kubectl docker.io
printf "${RED}Step 2/3: install k8s tools and Docker ${NC}\n"
apt-get update
apt-get install -y kubelet kubeadm kubectl docker.io
printf "${RED}Step 3/3: Join the cluster ${NC}\n"
kubeadm join --token $token $ip --discovery-token-ca-cert-hash $ca
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
else
echo "Invalid parameters";
cat help_worker.txt
fi