Watch
0
0
Fork
You've already forked hyperhive
0

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:
atlas 2026-11-23 17:20:22 +01:00 • committed by maia
commit 3cf89f25f1

View file

@ -107,17 +107,20 @@ let
# `toString` below so an unset `domain` reaches the assertion that names it
# instead of failing evaluation first.
controllerTcp = swarmCfg.controller.tcp;
# In the cluster the listener is the pod's `hostPort` on the node's address.
# The name the certificate is verified as stays `tcp.domain`
# (`controllerDial`), so the address needs no certificate of its own.
controllerAddress =
if deployCfg.swarm-controller.runtime == "k8s" then
deployCfg.swarm-controller.tcp.hostAddress
else
toString controllerTcp.domain;
# In the cluster the listener is behind a Service, which the host's resolver
# answers through the cluster's DNS. The upstream is a variable, so nginx asks
# the resolver per request: a name in the `proxy_pass` is looked up when the
# configuration loads, which fails the load while the cluster is not up and
# keeps the address of a Service that has since been recreated. The name the
# certificate is verified as stays `tcp.domain` (`controllerDial`), so the
# Service needs no certificate name of its own.
controllerOnCluster = deployCfg.swarm-controller.runtime == "k8s";
controllerUpstream =
if controllerTcp.enable then
"https://${controllerAddress}:${toString controllerTcp.port}"
if controllerOnCluster then
"https://$swarm_controller_upstream"
else
"https://${toString controllerTcp.domain}:${toString controllerTcp.port}"
else
"http://unix:${deployCfg.swarm-controller.socketPath}:";
# `proxy_http_version` and `Connection` because `recommendedProxySettings`,
@ -125,6 +128,10 @@ let
# them nginx speaks HTTP/1.0 to the upstream, which ends the SSE streams'
# keep-alive.
controllerDial = lib.optionalString controllerTcp.enable ''
${lib.optionalString controllerOnCluster ''
resolver ${config.services.hyperhive.network.bridgeIp} valid=10s ipv6=off;
set $swarm_controller_upstream ${deployCfg.swarm-controller.tcp.serviceHost}:${toString controllerTcp.port};
''}
${gatewayCfg.lib.verifiedProxyToWithClientCert (toString controllerTcp.domain) {
certificate = deployCfg.swarm-controller.tcp.gatewayClientCertFile;
key = deployCfg.swarm-controller.tcp.gatewayClientKeyFile;