K3S 集群配合Tailscale使用
前言
作者在上一篇文章介绍了使用 Tailscale 来作为 VPN 便于不同区域的 Server 和 Agent 连接
给自己挖了很多的坑(已经修正了)
这一篇重新讲一下 K3S 集群配合 Tailscale 使用。
⚠️:做东西前一定要看下官方文档呀,不然被自己挖的坑搞死了。
介绍

为了提高服务器的安全性,作者选择使用 Tailscale 来进行 Server 和 Agent 之间的联系。
绝对不是为了偷懒直接在现成服务器上搞的
安装
curl -fsSL https://tailscale.com/install.sh | sh
创建 Auth Key
位置:Setting -> Personal Settings -> Keys
新建 Key 替换文中的 auth-key。

调整 Tailscale ACL
确定集群将使用的 podCIDR(默认情况下 10.42.0.0/16)。在访问控制中附加以下部分:
"autoApprovers": {
"routes": {
"10.42.0.0/16": ["[email protected]"],
"2001:cafe:42::/56": ["[email protected]"],
},
},
未安装 K3S-Agent 的服务器
curl -sfL https://get.k3s.io | sh -s - agent \
--token mynodetoken \
--server https://myserver:6443 \
--vpn-auth "name=tailscale,joinKey=<auth-key>" \
--node-name k3s-agent- ## 可选
已安装 K3S-Agent 的服务器
- Server:编辑
/etc/systemd/system/k3s.service - Agent:编辑
/etc/systemd/system/k3s-agent.service
以下为其中的一个 Agent 的示例:
ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service 2>/dev/null'
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s \
agent \
'--node-name' \
'k3s-agent-hk-claw' \
+ '--vpn-auth' \
+ 'name=tailscale,joinKey=tskey-auth-key' \
重启服务
systemctl daemon-reload
systemctl restart k3s
然后观察服务的状态,如果所有的 INTERNAL-IP 都为你的实际 Tailscale IP,说明成功。
root@hk-hdcloud-d18:~# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k3s-agent-hk-claw Ready <none> 3h42m v1.32.4+k3s1 100.68.209.88 <none> Debian GNU/Linux 12 (bookworm) 6.1.0-35-cloud-amd64 containerd://2.0.4-k3s2
k3s-agent-jp-claw Ready <none> 3h41m v1.32.4+k3s1 100.120.219.98 <none> Debian GNU/Linux 12 (bookworm) 6.1.0-35-cloud-amd64 containerd://2.0.4-k3s2
k3s-server-hk-fox Ready control-plane,master 3h44m v1.32.4+k3s1 100.113.225.35 <none> Debian GNU/Linux 12 (bookworm) 6.1.0-32-cloud-amd64 containerd://2.0.4-k3s2