Created
March 13, 2025 16:21
-
-
Save itsjimbo/820d9aa73f335dcabec2a63009a377d3 to your computer and use it in GitHub Desktop.
multipass_cluster_example.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
source 0__base_include.sh | |
nodeCount=2 | |
read -p "How many worker nodes do you want?(default:$nodeCount) promt with [ENTER]:" inputNode | |
nodeCount="${inputNode:-$nodeCount}" | |
cpuCount=4 | |
read -p "How many cpus do you want per node?(default:$cpuCount) promt with [ENTER]:" inputCpu | |
cpuCount="${inputCpu:-$cpuCount}" | |
memCount=12 | |
read -p "How many gigabyte memory do you want per node?(default:$memCount) promt with [ENTER]:" inputMem | |
memCount="${inputMem:-$memCount}" | |
diskCount=60 | |
read -p "How many gigabyte diskspace do you want per node?(default:$diskCount) promt with [ENTER]:" inputDisk | |
diskCount="${inputDisk:-$diskCount}" | |
MASTER=$(echo "${CLUSTER_NAME}-master ") && WORKER=$(eval 'echo ${CLUSTER_NAME}-worker{1..'"$nodeCount"'}') | |
NODES+=$MASTER | |
NODES+=$WORKER | |
# Create containers | |
for NODE in ${NODES}; do multipass launch --name ${NODE} --cpus ${cpuCount} --mem ${memCount}G --disk ${diskCount}G; done | |
# Wait a few seconds for nodes to be up | |
sleep 5 | |
# Create the hosts file | |
cp /etc/hosts hosts.backup | |
cp /etc/hosts hosts | |
./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 /etc/hosts | |
echo "############################################################################" | |
echo "Writing multipass host entries to /etc/hosts on the VMs:" | |
for NODE in ${NODES}; do | |
multipass transfer hosts ${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 >> /etc/hosts' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment