run flannel's wireguard-native backend on every k8s node
This commit is contained in:
parent
6a50769269
commit
d09e2b403c
1 changed files with 225 additions and 29 deletions
|
|
@ -89,6 +89,13 @@ let
|
|||
${registryHost}:
|
||||
'';
|
||||
|
||||
# flannel's WireGuard backend listens on 51820/udp for IPv4 and names its
|
||||
# device `flannel-wg` (`ListenPort` and `createWGDev` in flannel v0.28's
|
||||
# `pkg/backend/wireguard/wireguard.go`, the version k3s 1.35 vendors). The
|
||||
# cluster is IPv4 only, so the IPv6 port and `flannel-wg-v6` do not exist.
|
||||
flannelWgPort = 51820;
|
||||
flannelWgIface = "flannel-wg";
|
||||
|
||||
# What the nodes of a cluster reach each other on, and the firewall rules
|
||||
# that admit those ports from the nodes' addresses and from no others. The
|
||||
# `extraCommands` run before the firewall's final refusal.
|
||||
|
|
@ -103,7 +110,7 @@ let
|
|||
}
|
||||
{
|
||||
proto = "udp";
|
||||
port = 8472;
|
||||
port = flannelWgPort;
|
||||
}
|
||||
{
|
||||
proto = "tcp";
|
||||
|
|
@ -164,7 +171,7 @@ in
|
|||
stay off. Pods and services take their
|
||||
addresses from {option}`services.hyperhive.deploy.k8s.podCidr` and
|
||||
{option}`services.hyperhive.deploy.k8s.serviceCidr`. The firewall
|
||||
trusts the pod network's interfaces (`cni0`, `flannel.1`), so the node
|
||||
trusts the pod network's interfaces (`cni0`, `flannel-wg`), so the node
|
||||
reaches its pods.
|
||||
'';
|
||||
};
|
||||
|
|
@ -219,7 +226,7 @@ in
|
|||
type = lib.types.listOf lib.types.str;
|
||||
default = [
|
||||
"cni0"
|
||||
"flannel.1"
|
||||
flannelWgIface
|
||||
];
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
|
|
@ -307,9 +314,11 @@ in
|
|||
description = ''
|
||||
The IPv4 addresses of the nodes that may join this cluster. The
|
||||
firewall admits the cluster's node-to-node ports (TCP 6443 for the API
|
||||
and the image mirror, TCP 10250 for the kubelet, UDP 8472 for flannel's
|
||||
VXLAN tunnel, TCP 5001 for the mirror's peers) from these addresses
|
||||
and from no others. Empty opens none of them. The firewall's
|
||||
and the image mirror, TCP 10250 for the kubelet, UDP 51820 for flannel's
|
||||
WireGuard tunnel, TCP 5001 for the mirror's peers) from these addresses
|
||||
and from no others. The tunnel authenticates its peers as well: a host
|
||||
that holds no key the cluster lists gets no frame onto the pod
|
||||
network, whatever address it sends from. Empty opens none of them. The firewall's
|
||||
iptables backend is required: the rules are not written for nftables.
|
||||
'';
|
||||
};
|
||||
|
|
@ -361,6 +370,23 @@ in
|
|||
services.hyperhive.deploy.k8s.enable = lib.mkDefault (enabledServices != [ ] && cfg.join == null);
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion =
|
||||
!(cfg.enable || cfg.join != null)
|
||||
|| !(lib.elem flannelWgPort (
|
||||
lib.catAttrs "listenPort" (
|
||||
lib.attrValues config.networking.wireguard.interfaces
|
||||
++ lib.attrValues config.networking.wg-quick.interfaces
|
||||
)
|
||||
));
|
||||
message = ''
|
||||
services.hyperhive.deploy.k8s runs flannel's WireGuard tunnel on UDP
|
||||
${toString flannelWgPort}, and a WireGuard interface of
|
||||
networking.wireguard.interfaces or networking.wg-quick.interfaces
|
||||
listens on it too: the second device cannot bind the port. Give that
|
||||
interface another listenPort.
|
||||
'';
|
||||
}
|
||||
{
|
||||
assertion = cfg.enable || cfg.join != null || enabledServices == [ ];
|
||||
message = ''
|
||||
|
|
@ -437,6 +463,7 @@ in
|
|||
"--data-dir=${dataDir}"
|
||||
"--cluster-domain=${clusterDomain}"
|
||||
"--cluster-dns=${clusterDns}"
|
||||
"--flannel-backend=wireguard-native"
|
||||
]
|
||||
++ lib.optional (cfg.address != null) "--tls-san=${cfg.address}";
|
||||
# k3s's own images come first: the mirror holds only the hyperhive
|
||||
|
|
@ -490,6 +517,9 @@ in
|
|||
serverAddr = "https://${cfg.join.server}:6443";
|
||||
tokenFile = joinToken.file;
|
||||
nodeIP = cfg.address;
|
||||
# `--flannel-backend` is a server flag: an agent takes the backend from
|
||||
# the server's config (`controlConfig.FlannelBackend` in k3s'
|
||||
# `pkg/agent/config/config.go`), so it runs WireGuard without a flag.
|
||||
# k3s's own images first, for the reason the server's are: a node with
|
||||
# no route to a public registry pulls nothing else.
|
||||
images = [ config.services.k3s.package.airgap-images ];
|
||||
|
|
|
|||
Loading…
Reference in a new issue