run the log store and its auth responders as pods
swarm-logs-auth and swarm-metrics-auth take --listen for a TCP address beside --socket. The log store is a Deployment on a static local volume that is its old container's data directory, behind a ClusterIP Service the gateway dials by name. Its two auth_request responders are one unpinned pod with a jwt role. The renderer gains a plain HTTP listener, a probe path, fsGroupChangePolicy, and one policy for a pod with both a listener and egress.
This commit is contained in:
parent
62c206169c
commit
dca4720b7b
4 changed files with 1385 additions and 746 deletions
|
|
@ -28,6 +28,8 @@ A service gets manifests on the host whose configuration deploys it:
|
|||
| `swarm-review-classifier` | Deployment | ServiceAccount |
|
||||
| `swarm-claude-login` | Deployment | ServiceAccount |
|
||||
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolume and Claim |
|
||||
| `swarm-victorialogs` | Deployment | Service, NetworkPolicy, PersistentVolume and Claim |
|
||||
| `swarm-logs-auth` | Deployment | ServiceAccount, two Services, NetworkPolicy |
|
||||
|
||||
`namespace.yaml` holds the Namespace ([Pod Security](#pod-security)).
|
||||
|
||||
|
|
@ -128,17 +130,23 @@ credential directory.
|
|||
(`collector`). The policy allows its pod on the queue's port too. The node trusts
|
||||
the pod network's interfaces, so without the policy a pod reaches every port of
|
||||
the host. A service without `egress` has no
|
||||
policy.
|
||||
policy. A service with a listener and `egress` (`swarm-logs-auth`) has the one
|
||||
policy: it admits the node to the listener and nothing else, and allows the
|
||||
egress above.
|
||||
- **Probes:** a service with an opt-in health listener gets its variable set to
|
||||
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
|
||||
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
|
||||
them, with `SWARM_CONTROLLER_HEALTH_ADDR`.
|
||||
them, with `SWARM_CONTROLLER_HEALTH_ADDR`. A third-party daemon with no health variable,
|
||||
`victoria-logs`, names a `probe` path instead (`/health`), which both probes
|
||||
request on its listener.
|
||||
- **Listener and init container:** a service with a TCP `listener`
|
||||
(`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`.
|
||||
containers is part of `system.build.k8sImages`. A listener with no `tlsDir`
|
||||
(`swarm-victorialogs`, `swarm-logs-auth`) serves plain HTTP: it gets the
|
||||
Service and the policy and no leaf, init container or renewal container.
|
||||
- **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
|
||||
|
|
@ -147,7 +155,13 @@ credential directory.
|
|||
daemon's binary, and the credential directory its unit loads from follows
|
||||
the daemon's name. The pod runs under one ServiceAccount, so a queue that
|
||||
holds two store roles has both bound to it
|
||||
([runtime](runtime.md#the-queue)).
|
||||
([runtime](runtime.md#the-queue)). The responders' pod of the log store holds a second container the same way
|
||||
([runtime](runtime.md#the-log-store)).
|
||||
- **A unit of the module's own making:** a service that never ran under systemd on the
|
||||
host (`swarm-victorialogs`, `swarm-logs-auth`) gives the renderer the
|
||||
`serviceConfig`, `environment` and `path` of one as a plain attribute set, with
|
||||
the daemon's flags as a list in `ExecStart`. The renderer reads nothing else of
|
||||
a unit. `fsGroupChangePolicy` in the entry sets the pod's field of that name.
|
||||
- **Config checksum:** a Deployment whose service has a ConfigMap (`etcFiles`)
|
||||
carries `checksum/etc` on its pod template, the hash of that ConfigMap's
|
||||
content, so a changed file rolls the pod.
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ says so with a label. The module sets the labels
|
|||
(`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`):
|
||||
|
||||
- `hyperhive.darkest.space/state-<service>=true`, one per service whose data
|
||||
the cluster keeps. Today that's `nats`, when `deploy.nats.enable` is on, and `ci-metrics`, when
|
||||
`deploy.ci-metrics.enable` is on. The
|
||||
the cluster keeps. Today that's `nats`, `ci-metrics` and `victorialogs`, each when its
|
||||
`deploy.<service>.enable` is on. The
|
||||
service's static local volume has a `nodeAffinity` on the label, and its pod a
|
||||
`nodeSelector` on it, so a node without the label can't run the pod and shows
|
||||
as no match instead of a volume that can't bind. One label per service, so
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
The swarm services that have a pod run in the host's cluster and nowhere else:
|
||||
`swarm-notify-router`, `swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
|
||||
`swarm-claude-login`, `swarm-controller` and the queue with its auth callout
|
||||
(`swarm-nats`). Each runs once per swarm, because two copies would share one
|
||||
`swarm-claude-login`, `swarm-controller`, the queue with its auth callout
|
||||
(`swarm-nats`) and the log store with its responders (`swarm-victorialogs`,
|
||||
`swarm-logs-auth`). Each runs once per swarm, because two copies would share one
|
||||
queue consumer and one set of buckets, or two cursors that push every CI run
|
||||
twice. A host that enables one gets [the cluster node](node.md) with it: no
|
||||
option moves a service between the host and the cluster, and the host has no
|
||||
|
|
@ -14,7 +15,7 @@ gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host.
|
|||
|
||||
`services.hyperhive.deploy.k8s.enable` defaults on where the host enables any
|
||||
of `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
|
||||
`claude-login`, `nats` or `swarm-controller`. `deploy.singleHostSwarm` and
|
||||
`claude-login`, `nats`, `swarm-controller` or `victorialogs`. `deploy.singleHostSwarm` and
|
||||
`deploy.allSwarmServices` enable them, so an all-local host gets the node and
|
||||
every service in the cluster with no further option. A host that sets
|
||||
`deploy.k8s.enable = false` while it enables one fails at evaluation, and the
|
||||
|
|
@ -55,6 +56,8 @@ The data stays where it was:
|
|||
([State](#state)).
|
||||
- The poller's cursor is `/var/lib/private/swarm-ci-metrics`, mounted the same
|
||||
way.
|
||||
- The log store's pod mounts `/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs`,
|
||||
the directory the container's store used ([The log store](#the-log-store)).
|
||||
- The other services keep nothing a move has to carry.
|
||||
|
||||
The pods log in to the store with their ServiceAccount tokens, so the store's
|
||||
|
|
@ -296,6 +299,77 @@ strategy, and the removed container stops before the pod can start.
|
|||
descriptors are the container runtime's, not the 800000 the container's unit
|
||||
sets. The VM test checks the runtime's is at least that.
|
||||
|
||||
## The log store
|
||||
|
||||
`swarm-victorialogs` is the swarm's log store: one VictoriaLogs, with the two
|
||||
`auth_request` responders of its gateway vhost in a second pod. The gateway's
|
||||
vhost `logs.<swarm domain>` stays on the host, and so do the collector that
|
||||
writes to the store and Grafana that reads it.
|
||||
|
||||
- **The store's pod.** The first service rendered without a unit of the module's
|
||||
own: the module defines the daemon's `ExecStart`, with its flags
|
||||
(`-storageDataPath`, `-httpListenAddr`, `-retentionPeriod`) as a list, and its
|
||||
`StateDirectory`, and the renderer reads the pod from those. The image holds
|
||||
the nixpkgs build of `victoria-logs` and nothing else. The pod serves plain
|
||||
HTTP on port 9428, probed on `/health`, logs in to nothing and pushes no
|
||||
telemetry: its output is the pod's log, which the host collector reads like
|
||||
any pod's ([logs](telemetry.md#logs)), and the collector scrapes the store's
|
||||
own metrics through the gateway. Its Deployment has one replica and the
|
||||
`Recreate` strategy, and the removed container stops before the pod can start.
|
||||
- **State.** The store's data directory is the container's own on the host,
|
||||
`/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs`: the claim
|
||||
`swarm-victorialogs-store` binds a static local volume on it, so an upgrade
|
||||
moves the process and not the bytes. Its `nodeAffinity` and the pod's
|
||||
`nodeSelector` both name the node label
|
||||
`hyperhive.darkest.space/state-victorialogs`
|
||||
([node labels](node.md#node-labels)), so the pod and the directory stay on the
|
||||
node that carries it. The files the container wrote belong to a user of its
|
||||
own, which the pod's user isn't. The pod's `fsGroup` is `65532`, and its
|
||||
`fsGroupChangePolicy` is `OnRootMismatch`: the first start after the upgrade
|
||||
gives the pod's group the whole tree, and later starts look at the directory
|
||||
alone, so a restart doesn't walk a store of many files. The files keep their
|
||||
user. The module makes the directory on a host that never ran the container,
|
||||
leaving the owner and mode of an existing one alone. The volume's capacity is
|
||||
nominal: a local volume's size isn't enforced, and retention
|
||||
(`deploy.victorialogs.retentionPeriod`, 30 days) is what bounds the store.
|
||||
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so the
|
||||
store serves TCP and a ClusterIP Service,
|
||||
`swarm-victorialogs.<namespace>.svc.<cluster domain>`, publishes it. The
|
||||
vhost's locations dial the Service's name through nginx's `resolver` (the
|
||||
hive's dnsmasq) and a variable, as [the controller's](#the-controller) do, so
|
||||
`gateway.dns.enable` has to be on. Each role has a variable of its own, because
|
||||
the auth subrequests run their own `set`. A `proxy_pass` with a variable and a
|
||||
URI part sends that URI and not the request's own, so the store's locations
|
||||
write none, and the request's path and query reach the store as the caller sent
|
||||
them. The collector's push, Grafana's datasource, the controller's and
|
||||
hive-c0re's query URLs and the agents' `swarm-logs` all use
|
||||
`logs.<swarm domain>`, which the host serves: none of them changes.
|
||||
- **The responders' pod.** `swarm-logs-auth`, which checks an agent's bearer and
|
||||
its `logs` permission, and `swarm-logs-grafana-auth` (the `swarm-metrics-auth`
|
||||
binary), which checks Grafana's, run as two containers of one Deployment,
|
||||
`swarm-logs-auth`. Both log in as the cert role `swarm-logs-auth` does, so the
|
||||
pod has one ServiceAccount and one jwt role of that name, and both read the
|
||||
store with the pod's token. They hold no state and nothing in the store pod
|
||||
calls them, so the pod has no node label and runs on any node, and only the
|
||||
gateway's subrequests (`auth_request`) reach them: each serves TCP
|
||||
(`--listen`) on 8081 and 8082, behind a Service each. A unix socket couldn't
|
||||
stay, because the host's nginx can't open a socket inside a pod, and Pod
|
||||
Security `restricted` refuses a `hostPath` for it.
|
||||
- **Who reaches what.** Both pods have a NetworkPolicy that selects them for
|
||||
ingress and allows none, so only the node's own traffic reaches them: the
|
||||
host's nginx, which dials the Services, and the kubelet's probes. The policy
|
||||
refuses a pod of the cluster. The store takes writes and reads with no credential, so a
|
||||
process on the host can read and write it: see
|
||||
[Agent security](../../2-handbook/agents/security.md). The responders' policy
|
||||
also lets the pod reach cluster DNS and the store's pod listener on the
|
||||
bridge's address (`egress = [ "store" ]`), the one host port the pod needs
|
||||
until the store moves into the cluster.
|
||||
- **The host's part.** The host keeps the vhost, `gateway.localNames` and the
|
||||
options (`retentionPeriod`, `authRate`, `authBurst`, `authVerdictTtl` and the
|
||||
store identity files). It runs no container, unit or socket directory for
|
||||
either pod, and no journal forwarder: the host collector reads the pods'
|
||||
output from the node like any pod's.
|
||||
|
||||
## Resources and sandbox
|
||||
|
||||
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
|
||||
|
|
@ -362,8 +436,9 @@ forwards.
|
|||
## Validation
|
||||
|
||||
`module-eval-k8s` checks that the all-local host runs every service as a pod and
|
||||
none as a container, unit or timer; that the node defaults on through the
|
||||
all-local mode and through one toggle, and an explicit `false` stays false; that a
|
||||
none as a container, unit or timer, and that the log store's volume is its
|
||||
old container's directory and its responders' pod has no node label; that the node
|
||||
defaults on through the all-local mode and through one toggle, and an explicit `false` stays false; that a
|
||||
host with the node off and a service on fails with a message naming the option
|
||||
and the services; that a controller without the TCP listener, the pod's bind
|
||||
address or the hive's resolver fails the evaluation; that the manifests sit in
|
||||
|
|
@ -409,4 +484,18 @@ listener refuses a client with no leaf. It runs the gateway's own controller
|
|||
location, from the module's text, against the pod: it answers an unsigned
|
||||
webhook 401. A changed rev rolls the Deployment onto a new pod.
|
||||
|
||||
The same VM test runs the log store. A unit of the test writes a record into the old
|
||||
container's data directory as another user before the cluster starts, because the
|
||||
container is no longer in the module to switch from. It asserts that the host has no
|
||||
container, unit or socket directory for the store or its responders; that the
|
||||
volume is that directory and the pod's group owns the tree; that a gateway, run
|
||||
from the module's own locations in a nginx of its own, returns the record to an
|
||||
agent's bearer, refuses an agent without the grant and a wrong secret, and
|
||||
checks Grafana's bearer with the second responder; that the store keeps a record
|
||||
posted to the ingest route and both records across a pod delete; and that the
|
||||
policy refuses a peer pod the Services while it admits the node and the
|
||||
kubelet. The `swarm-logs`
|
||||
CLI itself isn't run: it needs an agent's store certificate, so the test
|
||||
presents the `Authorization` header it sends.
|
||||
|
||||
`k8s-bao-login` and `k8s-node` check the store's login and the node.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
# Pod logs and metrics
|
||||
|
||||
The swarm's log and metric stores stay where they are. A pod's output reaches
|
||||
them through the hive collector that runs on the host
|
||||
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), so
|
||||
The swarm's metric store is a container on the host and its log store is a pod
|
||||
([the log store](runtime.md#the-log-store)). A pod's output reaches both
|
||||
through the hive collector that runs on the host
|
||||
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), which pushes to
|
||||
the stores through the gateway, so
|
||||
`swarm-logs query` and `swarm-metrics` show a pod's records next to the ones
|
||||
the same service produced as a host unit.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue