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 mara
commit 8cd6ae3037
3 changed files with 355 additions and 103 deletions

View file

@ -19,14 +19,14 @@ to the cluster, when the service's `runtime` says `"k8s"`.
A service gets manifests on the host whose configuration deploys it:
| service | workload | other objects |
| ------------------------- | ---------- | ------------------------------------------------------------------------------------------------ |
| `swarm-controller` | Deployment | ServiceAccount, PersistentVolumeClaim `swarm-controller-state`, ConfigMap `swarm-controller-etc` |
| `swarm-notify-router` | Deployment | ServiceAccount |
| `swarm-stt` | Deployment | ServiceAccount, NetworkPolicy `swarm-stt` |
| `swarm-review-classifier` | Deployment | ServiceAccount |
| `swarm-claude-login` | Deployment | ServiceAccount |
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolumeClaim `swarm-ci-metrics-state` |
| service | workload | other objects |
| ------------------------- | ---------- | ------------------------------------------------------------------------------------------ |
| `swarm-controller` | Deployment | ServiceAccount, ConfigMap `swarm-controller-etc`; Service, NetworkPolicy with the listener |
| `swarm-notify-router` | Deployment | ServiceAccount |
| `swarm-stt` | Deployment | ServiceAccount, NetworkPolicy `swarm-stt` |
| `swarm-review-classifier` | Deployment | ServiceAccount |
| `swarm-claude-login` | Deployment | ServiceAccount |
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolumeClaim `swarm-ci-metrics-state` |
`namespace.yaml` holds the Namespace. NATS with its auth responder has no
manifests yet: its image doesn't exist yet.
@ -133,11 +133,11 @@ credential directory.
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
them, with `SWARM_CONTROLLER_HEALTH_ADDR`.
- **Listener and init container:** a service with a TCP `listener`
(`swarm-controller`, with `swarm.controller.tcp.enable`) publishes its port on
the node's address with a `hostPort`, and gets an init container and a
renewal container that issue its leaf into an `emptyDir`
([runtime](runtime.md#the-controller)). The image of those containers is part
of `system.build.k8sImages`.
(`swarm-controller`, with `swarm.controller.tcp.enable`) publishes its port
with a ClusterIP Service, admits only the node to it with a NetworkPolicy, and
gets an init container and a renewal container that issue its leaf into an
`emptyDir` ([runtime](runtime.md#the-controller)). The image of those
containers is part of `system.build.k8sImages`.
- **More than the daemon:** a service whose pod holds more than its daemon
(the queue, whose server and exporter run beside the responder) names a
function in its entry that adds containers, init containers, volumes, host

View file

@ -69,6 +69,31 @@ these listeners without a firewall rule per port. Each service still
authenticates its callers: every listener of the secret store but its pods'
one refuses a connection without a client certificate.
## Reaching the cluster from the host
The host's resolver, the hive's dnsmasq (the host's own `/etc/resolv.conf`
names it), forwards the cluster's domain to CoreDNS. `deploy.k8s.clusterDomain`
is `cluster.local` and `deploy.k8s.clusterDns`, the tenth address of
`deploy.k8s.serviceCidr`, is the address k3s gives CoreDNS: the node passes
both as flags (`--cluster-domain`, `--cluster-dns`) and the resolver's
`server=/cluster.local/<address>` line reads the same values. A process on the
host, nginx included, so reaches a Service as
`<name>.<namespace>.svc.cluster.local`. The node doesn't set the line without
`gateway.dns.enable`, the option that runs that resolver.
A ClusterIP answers the host because kube-proxy (k3s runs it in `iptables`
mode) rewrites a host process's connection to the Service's address into the
pod's, and the firewall trusts the pod network's interfaces. The bridge's
agents ask the same resolver, so they get the same names. A name is no route:
the hive's egress rules decide whether the host forwards their traffic to the
cluster's addresses, and a pod's NetworkPolicy refuses what it forwards.
A pod that serves the host, such as the controller's, has a NetworkPolicy that
selects it for ingress and allows nothing. kube-router, the policy engine, adds
a rule at the top of every pod's chain that admits traffic from any address of
the node (`-m addrtype --src-type LOCAL`, commented "from local node"), so the
host reaches the pod and no other pod does.
## Logging in to the secret store
A pod holds no client certificate. It logs in to the secret store with a

View file

@ -93,9 +93,9 @@ Job:
delete. With no link, nothing went in, so the unit does nothing and needs no
cluster.
2. Wait for the cluster's API, then delete the service's Deployment, CronJob,
NetworkPolicy and ServiceAccount (selected by `app.kubernetes.io/name`), and
wait until its pods have gone. A pod exits 0 within its termination grace
period.
Service, NetworkPolicy and ServiceAccount (selected by
`app.kubernetes.io/name`), and wait until its pods have gone. A pod exits 0
within its termination grace period.
3. Delete the cluster's AddOn for the file, so that a later switch to `"k8s"`
applies the same manifest again. Then remove the renamed link.
@ -142,16 +142,24 @@ leader lock exists, so a cluster of more than one node needs one before the
controller may move there.
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so
the pod serves the TCP listener, and publishes it with a `hostPort` on
`deploy.swarm-controller.tcp.hostAddress`. That address is the hive bridge's
by default, the one the pods already reach the host's services on. The
the pod serves the TCP listener, and a ClusterIP Service,
`swarm-controller.<namespace>.svc.<cluster domain>`, publishes it. The
listener binds `0.0.0.0` inside the pod (`tcp.listenAddress`, which the
evaluation holds there). The gateway's `/api/` and `/webhook/forge/`
locations dial the node's address and port, and verify the listener's
certificate as `swarm.controller.tcp.domain` (`proxy_ssl_name`,
`proxy_ssl_verify`). With the controller on the host the locations dial the
name. A `hostPort` reaches one node: a cluster of more than one node needs a
Service instead.
evaluation holds there). The host's resolver, the hive's dnsmasq, hands the
cluster's domain to CoreDNS
([the node](node.md#reaching-the-cluster-from-the-host)). The gateway's
`/api/` and `/webhook/forge/` locations dial the Service's name through
nginx's own `resolver` (the same dnsmasq) and a variable upstream, so nginx
looks the name up per request. A name written into `proxy_pass` gets one
lookup when nginx loads its configuration, and nginx refuses to load when it
doesn't resolve. The locations verify the listener's certificate as
`swarm.controller.tcp.domain` (`proxy_ssl_name`, `proxy_ssl_verify`). With
the controller on the host the locations dial that name. The Service has a
NetworkPolicy that selects the pod for ingress and allows nothing: the
cluster's policy engine always admits traffic from an address of the node, so
the gateway's connection and the kubelet's probes reach the pod, and no other
pod does. A Service works on a cluster of more than one node, but the
controller's Deployment still has the one replica.
- **The listener's leaf.** The pod issues its own, from the store's
`swarm-controller-tls` role, with the same script as
`swarm-controller-tls.service`. An init container logs in with the pod's