-
Notifications
You must be signed in to change notification settings - Fork 26
/
1-deploy-multipass-vms.sh
executable file
·54 lines (43 loc) · 2.14 KB
/
1-deploy-multipass-vms.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
#!/bin/bash
# check if required applications and files are available
./utils/dependency-check.sh
nodeCount=2
read -p "How many worker nodes do you want?(default:$nodeCount) promt with [ENTER]:" inputNode
nodeCount="${inputNode:-$nodeCount}"
cpuCount=2
read -p "How many cpus do you want per node?(default:$cpuCount) promt with [ENTER]:" inputCpu
cpuCount="${inputCpu:-$cpuCount}"
memCount=4
read -p "How many gigabyte memory do you want per node?(default:$memCount) promt with [ENTER]:" inputMem
memCount="${inputMem:-$memCount}"
diskCount=20
read -p "How many gigabyte diskspace do you want per node?(default:$diskCount) promt with [ENTER]:" inputDisk
diskCount="${inputDisk:-$diskCount}"
k8sversion=1.27.11
read -p "Which k8s version do you want to use? check https://github.com/k3s-io/k3s/releases (default: $k8sversion, 1.28.7, 1.29.2) promt with [ENTER]:" inputK8Sversion
k8sversion="${inputK8Sversion:-$k8sversion}"
echo $k8sversion > k8sversion
MASTER=$(echo "k3s-master ") && WORKER=$(eval 'echo k3s-worker{1..'"$nodeCount"'}')
NODES+=$MASTER
NODES+=$WORKER
# Create containers
for NODE in ${NODES}; do multipass launch --name ${NODE} --cpus ${cpuCount} --memory ${memCount}G --disk ${diskCount}G --cloud-init cloud-config.yaml ; done
# Wait a few seconds for nodes to be up
sleep 5
# # create hosts files for multipass vms and cluster access with local environment
./utils/create-hosts.sh
echo "We need to write the host entries on your local machine to /etc/hosts"
echo "Please provide your sudo password:"
sudo cp hosts.local /etc/hosts
echo "############################################################################"
echo "Writing multipass host entries to /etc/hosts on the VMs:"
for NODE in ${NODES}; do
multipass transfer hosts.vm ${NODE}:
multipass transfer ~/.ssh/id_rsa.pub ${NODE}:
multipass exec ${NODE} -- sudo iptables -P FORWARD ACCEPT
multipass exec ${NODE} -- bash -c 'sudo cat /home/ubuntu/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys'
multipass exec ${NODE} -- bash -c 'sudo chown ubuntu:ubuntu /etc/hosts'
multipass exec ${NODE} -- bash -c 'sudo cat /home/ubuntu/hosts.vm >> /etc/hosts'
done
# cleanup tmp hostfiles
rm hosts.vm