K3S 集群配合Tailscale使用

字号
字体
版心
外观
天空

K3S 集群配合Tailscale使用

I

Incohua

•3 分钟阅读

前言#

作者在上一篇文章介绍了使用 Tailscale 来作为 VPN 便于不同区域的 Server 和 Agent 连接

给自己挖了很多的坑(已经修正了)

这一篇重新讲一下 K3S 集群配合 Tailscale 使用。

官方文档的部分说明K3s 集群可以部署在没有共同私有网络、无法直连的节点上(例如,位于不同公有云中的节点)。实现这一部署有两种方案:使用嵌入式 K3s 多云解决方案,或者与 tailscale VPN 集成。docs.k3s.io

⚠️:做东西前一定要看下官方文档呀,不然被自己挖的坑搞死了。

介绍#

为了提高服务器的安全性,作者选择使用 Tailscale 来进行 Server 和 Agent 之间的联系。

绝对不是为了偷懒直接在现成服务器上搞的

安装#

bash
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)。在访问控制中附加以下部分:

json
"autoApprovers": {
        "routes": {
            "10.42.0.0/16":        ["your_account@xyz.com"],
            "2001:cafe:42::/56": ["your_account@xyz.com"],
        },
    },

未安装 K3S-Agent 的服务器#

bash
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 的示例:

text
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' \

重启服务#

bash
systemctl daemon-reload
systemctl restart k3s

然后观察服务的状态,如果所有的 INTERNAL-IP 都为你的实际 Tailscale IP,说明成功。

bash
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
text

评论 0

按时间排序
评论还没开通
  1. 还没有评论。