-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-k8s-cluster
executable file
·42 lines (36 loc) · 1.29 KB
/
create-k8s-cluster
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
#!/bin/bash
echo "Configuring hosts..."
for node in ts{1..4}; do
ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${node}.maas"
echo "$node: uploading configuration"
scp ./resource/config-k8s-host $node:
echo "$node: Base configuring"
ssh $node "sudo node=$node ./config-k8s-host" &
echo PID[${node: -1}]=$!
PID[${node: -1}]=$!
done
wait ${PID[*]}
unset PID
echo "Base configured all hosts"
echo "Setting up master"
ssh ts1 'sudo kubeadm init -- --apiserver-cert-extra-sans=ts1.maas --pod-network-cidr=192.168.0.0/16'
ssh ts1 'mkdir -p $HOME/.kube'
ssh ts1 'sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config'
ssh ts1 'sudo chown $(id -u):$(id -g) $HOME/.kube/config'
echo "Configuring CNI"
scp ./resource/calico.yaml ts1:
ssh ts1 'kubectl apply -f $HOME/calico.yaml'
echo "Setting up workers"
JOIN=$(ssh -o StrictHostKeyChecking=no ts1 \
"sudo kubeadm token create --print-join-command")
for node in ts{2..4}; do
echo "$node: joining as worker"
ssh -o StrictHostKeyChecking=no $node "sudo $JOIN"
PID[$node]=$!
done
wait ${PID[*]}
scp ./resource/{svc_acct.yaml,cluster_role_binding.yaml,kubernetes-dashboard.yaml} ts1:
ssh ts1 'kubectl apply -f $HOME/svc_acct.yaml'
ssh ts1 'kubectl apply -f $HOME/cluster_role_binding.yaml'
ssh ts1 'kubectl apply -f $HOME/kubernetes-dashboard.yaml'
echo "done"