Watch
0
0
Fork
You've already forked hyperhive
0

k8s: the queue's client port is a loadbalancer service

The queue's client port was a hostPort on 0.0.0.0, which Pod Security baseline and restricted forbid. It is a LoadBalancer Service now, which k3s's service load balancer binds on every address of the node with a hostPort of its own in kube-system, so hives on other hosts keep their URL. No node port is allocated. The stt policy allows the load balancer's pods in place of the queue's, and the prune unit waits for them to go before the host unit starts. The egress published-port rule and the raw-table rules apply to the load balancer's hostPort as to the pod's.
This commit is contained in:
atlas 2026-11-23 19:09:02 +01:00 • committed by mara
commit 796fd6201f

View file

@ -984,13 +984,11 @@ let
image = ref server;
imagePullPolicy = "Never";
args = lib.tail (lib.splitString " " natsSystem.systemd.services.nats.serviceConfig.ExecStart);
# Every address of the node, which is where the queue listens today.
# The port the client Service targets.
ports = [
{
name = "client";
containerPort = cfg.port;
hostPort = cfg.port;
hostIP = "0.0.0.0";
}
];
# The monitor is on the pod's loopback, so the probe runs in the
@ -1108,6 +1106,34 @@ let
];
};
};
# The client port, on every address of the node, which is where the
# queue listens in its container, so the hives of other hosts keep their
# URL. The cluster's service load balancer (k3s's servicelb) binds the
# Service's port on each node with a `hostPort` of its own, in
# `kube-system`, and forwards it to the pod through the Service. It does
# that by the Service's cluster address, so no node port is needed, and
# none is allocated: a node port would be a second way in, which the
# raw-table rules (./lib/swarm-nats-raw-rules.nix) don't name. The server
# sees the load balancer's pod as the client, not the client's address.
objects."${machine}/loadbalancer" = {
apiVersion = "v1";
kind = "Service";
metadata = metaFor machine;
spec = {
type = "LoadBalancer";
allocateLoadBalancerNodePorts = false;
selector = (metaFor machine).labels;
ports = [
{
name = "client";
protocol = "TCP";
port = cfg.port;
targetPort = "client";
}
];
};
};
objects."${machine}/networkpolicy" = {
apiVersion = "networking.k8s.io/v1";
kind = "NetworkPolicy";
@ -1615,13 +1641,15 @@ in
# sets no listen host), so reachability is the firewall alone.
networking.firewall.allowedTCPPorts = lib.mkIf deployCfg.nats.openFirewall [ cfg.port ];
# The pod's client `hostPort` is a DNAT rule, which the INPUT rules above
# never see: ./lib/swarm-nats-raw-rules.nix gives it the container's reach.
services.hyperhive.network.enable = lib.mkIf onK8s (lib.mkDefault true);
# An agent dials the queue at the bridge's address; the pod's `hostPort` is
# forwarded to the cluster, which the egress forward chain would refuse.
# An agent dials the queue at the bridge's address, and the load
# balancer's `hostPort` forwards that to the cluster, which the egress
# forward chain would refuse.
services.hyperhive.deploy.hive-controller.egress.publishedPorts = lib.mkIf onK8s [ cfg.port ];
# The load balancer's `hostPort` is a DNAT rule, which the INPUT rules above
# never see: ./lib/swarm-nats-raw-rules.nix gives it the container's reach.
networking.firewall.extraCommands = lib.mkIf onK8s (
import ./lib/swarm-nats-raw-rules.nix { inherit lib; } {
chain = "nixos-fw-nats";