Skip to content

Instantly share code, notes, and snippets.

@bukowa
Last active November 2, 2022 14:21
Show Gist options
  • Save bukowa/18eae987ffdcf68e753da29ffa7145f5 to your computer and use it in GitHub Desktop.
Save bukowa/18eae987ffdcf68e753da29ffa7145f5 to your computer and use it in GitHub Desktop.
bootstrap install k3s via ssh on alpine
#!/bin/sh
export SERVER1="192.168.0.201"
export SERVER2="192.168.0.202"
export SERVER3="192.168.0.203"
export SERVER4="192.168.0.204"
export HOST1="g3w.dell.baza"
export HOST2="g50.dell.baza"
export HOST3="h3m.dell.baza"
export HOST3="g73.dell.baza"
#!/bin/sh
# alpine
set -eu
apk update
apk add wireguard-tools
rc-update add cgroups default
rc-service cgroups start
swapoff -a
curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_ENABLE=true sh -
k3s check-config
#!/bin/bash
set -eux
source .env.sh
# shellcheck disable=SC2029
init() {
ssh "root@${1}" "curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC=\"
server
--cluster-init
--tls-san=${1}
--disable=traefik
--node-external-ip=${1}
--flannel-backend=wireguard-native
--flannel-external-ip
\" \
INSTALL_K3S_CHANNEL='stable' sh -"
}
# shellcheck disable=SC2029
join_agent() {
ssh "root@${2}" "curl -sfL https://get.k3s.io | \
INSTALL_K3S_EXEC=\"
server
--server=https://${1}:6443
--token=${TOKEN}
--tls-san=${2}
--disable=traefik
--node-external-ip=${2}
--flannel-backend=wireguard-native
--flannel-external-ip
\" \
INSTALL_K3S_CHANNEL='stable' sh -"
}
init "${SERVER1}"
until TOKEN="$(ssh "root@${SERVER1}" cat /var/lib/rancher/k3s/server/node-token)"
do
sleep 3
done
join_agent "${SERVER1}" "${SERVER2}"
join_agent "${SERVER1}" "${SERVER3}"
join_agent "${SERVER1}" "${SERVER4}"
scp root@"${SERVER1}":/etc/rancher/k3s/k3s.yaml $(pwd) && sed -i "s/127.0.0.1/${SERVER1}/g" k3s.yaml && export KUBECONFIG=$PWD/k3s.yaml
#!/bin/bash
set -e
source .env.sh
echo "Are you sure?"; read -r
delete() {
ssh "root@${1}" "rc-service k3s stop || true && /usr/local/bin/k3s-uninstall.sh" || true
}
delete "${SERVER1}"
delete "${SERVER2}"
delete "${SERVER3}"
delete "${SERVER4}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment