Skip to content

Instantly share code, notes, and snippets.

@lkj4
Created June 20, 2021 16:46
Show Gist options
  • Save lkj4/5334042a0311784dbdacfad50907f463 to your computer and use it in GitHub Desktop.
Save lkj4/5334042a0311784dbdacfad50907f463 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
nodes=(`terraform output -raw ips`)
rm ~/.ssh/known_hosts
install_k3s () {
if [ $run -gt 2 ]; then
role="agent"
disable_traefik=""
disable_servicelb=""
fi
ssh-keyscan -H $1 >> ~/.ssh/known_hosts
sleep .5
ssh root@$1 "swapoff -a"
ssh root@$1 "curl -sfL https://get.k3s.io | \
INSTALL_K3S_CHANNEL=latest \
INSTALL_K3S_VERSION=v1.21.0+k3s1 \
sh -s - \
$role \
$init_or_join \
$disable_traefik \
$disable_servicelb \
--node-external-ip $1"
if [ $run -eq 0 ]; then
sleep 3
token=`ssh root@${nodes[0]} cat /var/lib/rancher/k3s/server/token`
init_or_join=" --server https://${nodes[0]}:6443 --token $token"
fi
((++run))
}
run=0
role="server"
disable_traefik="--disable traefik"
disable_servicelb="--disable servicelb"
init_or_join=" --cluster-init"
for e in ${nodes[*]}; do
install_k3s $e
done
ssh root@${nodes[0]} cat /etc/rancher/k3s/k3s.yaml | sed "s/127.*:/${nodes[0]}:/g" > kubeconfig.yaml
set +x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment