
我嘗試為 K3s 多站點叢集配置 Wireguard,我的問題是路由。至少有 4 個節點,一個位置 2 個,其他位置 1 個,其他位置 + 1 個。
假設:
- 10.50.0.0/16網路用於實體節點
- 10.42.0.0/16 網路用於 Pod
- 10.43.0.0/16網路用於服務
- 每個實體節點可以建立一個Pod,並分配一個唯一的IP位址,範圍為10.42.0.0/16
- 每個實體節點上的每個 Pod 應該能夠互相 ping 通
部署的配置僅在最後兩個節點之間有效,其餘節點甚至無法互相 ping 通。我猜這可能與路由有關,但我沒有足夠的知識來檢查這一點。
來自兩個節點的範例配置:
10.50.54.100:
[Interface]
# primary-1
Address = 10.50.54.100/24
PrivateKey = pr111111111111111111111111111111111111111111
ListenPort = 443
MTU = 1500
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward
PostUp = ufw allow 443/udp || true
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
PostDown = sysctl -w -q net.ipv4.ip_forward=0
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward
[Peer]
# infra-1
PublicKey = pub11111111111111111111111111111111111111111
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = xxxxxxxxxx:443
[Peer]
# compute-2
PublicKey = pub2222222222222222222222222222222222222222
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = yyyyyyyyyy:443
[Peer]
# storage-1
PublicKey = pub3333333333333333333333333333333333333333
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = zzzzzzzzzzz:443
10.50.54.2:
[Interface]
# infra-1
Address = 10.50.54.2/24
PrivateKey = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ListenPort = 443
MTU = 1500
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward
PostUp = ufw allow 51820/udp || true
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
PostDown = sysctl -w -q net.ipv4.ip_forward=0
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward
[Peer]
# primary-1
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = xxxxxxxxxxxx:443
[Peer]
# compute-2
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = yyyyyyyyyyy:443
[Peer]
# storage-1
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.50.54.0/16, 10.42.0.0/16, 10.43.0.0/16
PersistentKeepalive = 15
Endpoint = zzzzzzzzzzzz:443
你有什麼線索嗎? Wireguard 應該如何設計?為什麼這個配置不起作用?
謝謝!
答案1
(抱歉,這可能應該是一條評論,因為我不能 100% 確定它是否正確,但我在這個網站上還沒有足夠的代表來使用評論。)
我相信AllowedIPs
每個都[Peer]
需要是唯一的(即不重疊的範圍),因為這就是 WireGuard 知道將給定的出站資料包路由到哪個對等點的方式。如果是這樣,您需要為每個網站設定單獨的 IP 範圍(對於 Pod 和服務 - 節點不重要)。
我從來沒有真正嘗試過重疊範圍來看看它會做什麼,並且文檔對此並不完全清楚,但它似乎暗示這不受支援。 (如果支援的話,要么必須將每個資料包廣播到AllowedIPs
包含資料包目標位址的所有對等點,要么使用 ARP 之類的東西來動態確定路由。)
我不太熟悉k3s
,所以不確定它的多站點叢集是如何運作的——這基本上只是集中管理的多個獨立的 Kubernetes 叢集嗎?