Skip to content

Instantly share code, notes, and snippets.

@mogwai
Last active April 4, 2020 11:31
Show Gist options
  • Save mogwai/bae05f37b01b32f8a49918f69dc31f2a to your computer and use it in GitHub Desktop.
Save mogwai/bae05f37b01b32f8a49918f69dc31f2a to your computer and use it in GitHub Desktop.
Setup k3s VMs
# Install multipass
sudo snap install multipass --classic
# Launch nodes
multipass launch -n master & multipass launch -n node1 & multipass launch -n node2
# Download, transfer and run master install script
curl -sfL https://get.k3s.io > k3s.sh
multipass transfer k3s.sh master:
multipass exec master bash k3s.sh
# Get k8s joining token from master
multipass exec master sudo cat /var/lib/rancher/k3s/server/node-token > token
# Get master ip
multipass ls | grep master | awk '{print $3}' > masterip
# Create script to join to master node
echo 'curl -sfL https://get.k3s.io | K3S_URL=https://'$(cat masterip):6443' K3S_TOKEN='$(cat token) sh - > node_join.sh
# Trasnfer scripts to node vms
multipass transfer node_join.sh node1:
multipass transfer node_join.sh node2:
# Run script on node vms
multipass exec node1 bash node_join.sh & multipass exec node2 bash node_join.sh
# Get kubectl configuration file
multipass exec master sudo cat /etc/rancher/k3s/k3s.yaml > k3s.yaml
# Use ip of master in config
cat k3s.yaml | sed "s/127.0.0.1/$(cat masterip)/" >> k3s.yaml
# Confirm that we can see nodes
kubectl get nodes --kubeconfig k3s.yaml -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment