Skip to content

Instantly share code, notes, and snippets.

@devfire
Created February 3, 2022 19:20
Show Gist options
  • Save devfire/fdc2bfc7e0cfcbfd027636fbfa7259d1 to your computer and use it in GitHub Desktop.
Save devfire/fdc2bfc7e0cfcbfd027636fbfa7259d1 to your computer and use it in GitHub Desktop.
multipass+k3s bootstrap
for node in node1 node2 node3;do
echo launching $node
multipass launch -n $node
done
# Init cluster on node1
echo init cluster
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
# Get node1's IP
IP=$(multipass info node1 | grep IPv4 | awk '{print $2}')
echo master node ip is $IP
# Get Token used to join nodes
TOKEN=$(multipass exec node1 sudo cat /var/lib/rancher/k3s/server/node-token)
# Join node2
echo joining node2...
multipass exec node2 -- \
bash -c "curl -sfL https://get.k3s.io | K3S_URL=\"https://$IP:6443\" K3S_TOKEN=\"$TOKEN\" sh -"
echo ...joined!
# Join node3
echo joining node3...
multipass exec node3 -- \
bash -c "curl -sfL https://get.k3s.io | K3S_URL=\"https://$IP:6443\" K3S_TOKEN=\"$TOKEN\" sh -"
echo ...joined!
# Get cluster's configuration
echo writing out cluster config yaml
multipass exec node1 sudo cat /etc/rancher/k3s/k3s.yaml > k3s.yaml
# Set node1's external IP in the configuration file
sed -i "s/127.0.0.1/$IP/" k3s.yaml
# We'r all set
echo
echo "K3s cluster is ready !"
echo
echo "Run the following command to set the current context:"
echo "$ export KUBECONFIG=$PWD/k3s.yaml"
echo
echo "and start to use the cluster:"
echo "$ kubectl get nodes"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment