move flannel's wireguard port to 51830, advertise the node address as the tunnel endpoint, drop the 51820 assertion
This commit is contained in:
parent
d09e2b403c
commit
1a9fab57f5
1 changed files with 194 additions and 77 deletions
|
|
@ -89,12 +89,42 @@ 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;
|
||||
# flannel's WireGuard backend names its device `flannel-wg` and binds
|
||||
# `ListenPort` (`createWGDev` and `RegisterNetwork` in flannel v0.28's
|
||||
# `pkg/backend/wireguard/wireguard.go`, the version k3s 1.35 vendors), whose
|
||||
# default, 51820, is the port of a host's own `wg0` in the semi-spread
|
||||
# example. k3s writes the backend's config itself and has no option for the
|
||||
# port, so the node hands it a net-conf through `--flannel-conf`
|
||||
# (`pkg/executor/embed/embed.go`: a given file is used as is). The fields are
|
||||
# the ones k3s's own template fills (`flannelConf` and `wireguardNativeBackend`
|
||||
# in `pkg/agent/flannel/setup.go`) for an IPv4-only cluster, so there is no
|
||||
# IPv6 port or `flannel-wg-v6`.
|
||||
flannelWgPort = 51830;
|
||||
flannelWgIface = "flannel-wg";
|
||||
flannelNetConf = pkgs.writeText "flannel-net-conf.json" (
|
||||
builtins.toJSON {
|
||||
Network = cfg.podCidr;
|
||||
EnableIPv4 = true;
|
||||
EnableIPv6 = false;
|
||||
IPv6Network = "::/0";
|
||||
Backend = {
|
||||
Type = "wireguard";
|
||||
PersistentKeepaliveInterval = 25;
|
||||
ListenPort = flannelWgPort;
|
||||
};
|
||||
}
|
||||
);
|
||||
# flannel binds the tunnel to the interface of the default route and names
|
||||
# that interface's address as the peers' endpoint (`LookupExtInterface` in
|
||||
# k3s' `pkg/agent/flannel/flannel.go`) unless the node has an external IP and
|
||||
# the server runs `--flannel-external-ip`, which makes the endpoint that IP
|
||||
# (the `public-ip-overwrite` annotation, `pkg/subnet/kube/kube.go` in
|
||||
# flannel). A node with an `address` advertises it, so the tunnel runs on
|
||||
# the address the firewall admits whatever the default route is.
|
||||
flannelFlags = [
|
||||
"--flannel-conf=${flannelNetConf}"
|
||||
]
|
||||
++ lib.optional (cfg.address != null) "--node-external-ip=${cfg.address}";
|
||||
|
||||
# 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
|
||||
|
|
@ -185,7 +215,8 @@ in
|
|||
({option}`services.hyperhive.network.bridgeIp`) nor
|
||||
{option}`services.hyperhive.deploy.k8s.serviceCidr`, nor any network
|
||||
the host routes to. k3s's own default, `10.42.0.0/16`, contains the
|
||||
hive bridge's default subnet.
|
||||
hive bridge's default subnet. A host that joins sets the same value as
|
||||
the main node: its flannel reads the range from this option.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -222,6 +253,17 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
flannelWgPort = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = flannelWgPort;
|
||||
description = ''
|
||||
The UDP port flannel's WireGuard tunnel listens on. The firewall admits
|
||||
it from the nodes' addresses.
|
||||
'';
|
||||
};
|
||||
|
||||
cniInterfaces = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [
|
||||
|
|
@ -297,10 +339,11 @@ in
|
|||
example = "192.168.1.10";
|
||||
description = ''
|
||||
The address the other nodes of the cluster reach this node on. Set, it
|
||||
is the node's IP (`--node-ip`), so flannel's tunnel endpoint and the
|
||||
node's registered address are it, and a server also lists it in its API
|
||||
is the node's IP (`--node-ip`) and its external IP
|
||||
(`--node-external-ip`), so the node's registered address and flannel's
|
||||
tunnel endpoint are it, and a server also lists it in its API
|
||||
certificate (`--tls-san`). Null leaves k3s to pick the address of the
|
||||
default route.
|
||||
default route for the node and for the tunnel.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -314,7 +357,7 @@ 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 51820 for flannel's
|
||||
and the image mirror, TCP 10250 for the kubelet, UDP ${toString flannelWgPort} 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
|
||||
|
|
@ -370,23 +413,6 @@ 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 = ''
|
||||
|
|
@ -464,7 +490,9 @@ in
|
|||
"--cluster-domain=${clusterDomain}"
|
||||
"--cluster-dns=${clusterDns}"
|
||||
"--flannel-backend=wireguard-native"
|
||||
"--flannel-external-ip"
|
||||
]
|
||||
++ flannelFlags
|
||||
++ lib.optional (cfg.address != null) "--tls-san=${cfg.address}";
|
||||
# k3s's own images come first: the mirror holds only the hyperhive
|
||||
# images, so the node pulls nothing else, not even CoreDNS.
|
||||
|
|
@ -519,7 +547,9 @@ in
|
|||
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.
|
||||
# `pkg/agent/config/config.go`). The net-conf is read from the node's own
|
||||
# file, so the agent names it too, with the pod range the server runs.
|
||||
extraFlags = flannelFlags;
|
||||
# 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