k8s: the controller's listener is a ClusterIP service the host dials by name
The controller's api port was a hostPort on the node, which Pod Security baseline and restricted forbid. It is a ClusterIP Service now, behind a NetworkPolicy that admits only the node. The host's resolver (the hive's dnsmasq) forwards cluster.local to CoreDNS, and the gateway dials the Service by name through nginx's resolver. tcp.hostAddress goes.
This commit is contained in:
parent
2c1dc695c5
commit
9a72d07c05
1 changed files with 355 additions and 103 deletions
|
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
# `deploy.swarm-controller.runtime = "k8s"` runs the daemon as a pod in this
|
||||
# host's cluster instead (./k8s/render.nix renders it from the unit below). The
|
||||
# unit is then disabled, and the gateway dials the pod's `hostPort`.
|
||||
# unit is then disabled, and the gateway dials the pod's Service by name.
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
|
|
@ -635,7 +635,8 @@ in
|
|||
The pod needs the TCP listener
|
||||
({option}`services.hyperhive.swarm.controller.tcp.enable`): the host
|
||||
cannot reach a unix socket inside a pod, so the gateway dials the
|
||||
listener on {option}`tcp.hostAddress`. The pod's state directory is an
|
||||
listener, which a Service in the cluster publishes at
|
||||
{option}`tcp.serviceHost`. The pod's state directory is an
|
||||
`emptyDir`: the operator grant record is in the queue's key-value
|
||||
store, and what is left in the directory (the forge avatar markers, the
|
||||
legacy webhook secret the store also holds) is made again at start. A
|
||||
|
|
@ -790,23 +791,22 @@ in
|
|||
|
||||
With {option}`services.hyperhive.deploy.swarm-controller.runtime` set
|
||||
to `k8s` this is the bind inside the pod, so it must stay `0.0.0.0`.
|
||||
The node's address is {option}`hostAddress`.
|
||||
'';
|
||||
};
|
||||
|
||||
hostAddress = lib.mkOption {
|
||||
serviceHost = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.services.hyperhive.network.bridgeIp;
|
||||
defaultText = lib.literalExpression "config.services.hyperhive.network.bridgeIp";
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = "swarm-controller.${config.services.hyperhive.k8s.namespace}.svc.${config.services.hyperhive.deploy.k8s.clusterDomain}";
|
||||
defaultText = lib.literalExpression ''"swarm-controller.<namespace>.svc.<cluster domain>"'';
|
||||
description = ''
|
||||
With {option}`services.hyperhive.deploy.swarm-controller.runtime` set
|
||||
to `k8s`: the node address the pod's `hostPort` binds and the gateway
|
||||
dials. The default is the hive bridge's address, the one the pods
|
||||
already reach the host's services on. The gateway verifies the
|
||||
listener's certificate as
|
||||
{option}`services.hyperhive.swarm.controller.tcp.domain`, not as
|
||||
this address. A `hostPort` reaches one node: a cluster of several
|
||||
nodes needs a Service instead.
|
||||
to `k8s`: the name of the Service in front of the pod's listener,
|
||||
which the gateway dials. The host's resolver answers it through the
|
||||
cluster's DNS. The gateway verifies the listener's certificate as
|
||||
{option}`services.hyperhive.swarm.controller.tcp.domain`, not as this
|
||||
name.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -939,8 +939,8 @@ in
|
|||
users.groups.swarm-controller = { };
|
||||
users.groups.${clientsGroup} = { };
|
||||
|
||||
# The pod's `hostPort` is on the hive bridge's address by default, and the
|
||||
# cluster's pods reach the host's services through the bridge.
|
||||
# The cluster's pods reach the host's services through the bridge, and the
|
||||
# host's resolver (the hive's dnsmasq, on the bridge) answers the Service's name.
|
||||
services.hyperhive.network.enable = lib.mkIf onK8s (lib.mkDefault true);
|
||||
|
||||
# Through the unit, not `users.users.nginx.extraGroups`: systemd resolves
|
||||
|
|
@ -1028,8 +1028,16 @@ in
|
|||
services.hyperhive.deploy.swarm-controller.tcp.listenAddress is
|
||||
"${tcpHost.listenAddress}", and with runtime = "k8s" it is the bind
|
||||
inside the pod, where any address but "0.0.0.0" leaves the listener
|
||||
unbound and the pod NotReady. Leave it at "0.0.0.0"; the node's
|
||||
address is services.hyperhive.deploy.swarm-controller.tcp.hostAddress.
|
||||
unbound and the pod NotReady. Leave it at "0.0.0.0".
|
||||
'';
|
||||
}
|
||||
{
|
||||
assertion = !onK8s || config.services.hyperhive.gateway.dns.enable;
|
||||
message = ''
|
||||
services.hyperhive.deploy.swarm-controller.runtime = "k8s" needs
|
||||
services.hyperhive.gateway.dns.enable: the gateway dials the pod's
|
||||
Service by name, and the hive's resolver is what hands the cluster's
|
||||
domain to its DNS. Set it, or leave the controller's runtime at "host".
|
||||
'';
|
||||
}
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue