Last active
October 29, 2024 17:56
-
-
Save eggplants/c39cb7a8bafd6177321f4e28a999c7cd to your computer and use it in GitHub Desktop.
Tailscale + k3s on RaspberryPi 4
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
#!/usr/bin/env bash | |
# === | |
# > master node & agent node(s) | |
# === | |
sudo apt update -y && sudo apt upgrade -y | |
sudo systemctl stop dphys-swapfile | |
sudo systemctl disable dphys-swapfile | |
sudo rm -f /var/swap | |
echo 'NTP=ntp.nict.jp' | sudo tee -a /etc/systemd/timesyncd.conf | |
sudo systemctl restart systemd-timesyncd | |
curl -fsSL https://tailscale.com/install.sh | sh | |
sudo tailscale up | |
curl https://mise.run | sh | |
echo 'eval "$($HOME/.local/bin/mise activate bash)"' >>~/.bashrc | |
eval "$($HOME/.local/bin/mise activate bash)" | |
mise use --global python@latest | |
mise use --global go@latest | |
echo "$(</boot/firmware/cmdline.txt) cgroup_memory=1 cgroup_enable=memory" > cmdline.txt | |
cat cmdline.txt | sudo tee /boot/firmware/cmdline.txt | |
rm cmdline.txt | |
sudo reboot | |
# === | |
# > master node | |
# === | |
MASTER_NODE_IP="$(tailscale status | awk 'NR==1{print$1}')" | |
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --flannel-iface tailscale0 --advertise-address $MASTER_NODE_IP --node-ip $MASTER_NODE_IP --node-external-ip $MASTER_NODE_IP" sh -s | |
sudo k3s token create # get token | |
# === | |
# > agent node(s) | |
# === | |
K3S_MASTER_TOKEN="..." | |
MASTER_NODE_HOSTNAME="pi01" | |
MASTER_NODE_IP="$(tailscale status | awk -v m="$MASTER_NODE_HOSTNAME" '$2==m{print$1}')" | |
AGENT_NODE_IP="$(tailscale status | awk 'NR==1{print$1}')" | |
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent --server https://${MASTER_NODE_IP}:6443 --token $K3S_MASTER_TOKEN --flannel-iface tailscale0 --node-ip $AGENT_NODE_IP --node-external-ip $AGENT_NODE_IP" sh -s | |
# check service status is up | |
systemctl status k3s-agent.service | |
# === | |
# > master node | |
# === | |
# check nodes | |
sudo k3s kubectl get nodes | |
# NAME STATUS ROLES AGE VERSION | |
# pi01 Ready control-plane,master 21m v1.30.5+k3s1 | |
# pi02 Ready <none> 9m24s v1.30.5+k3s1 | |
# pi03 Ready <none> 5m27s v1.30.5+k3s1 | |
# pi04 Ready <none> 2m33s v1.30.5+k3s1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment