Watch
0
0
Fork
You've already forked hyperhive
0

run grafana as a pod in the cluster

The Deployment swarm-grafana replaces the swarm-grafana container: one
replica on a static local volume that is the container's data directory,
an init container that fetches the OIDC client secret and creates the
administrator password, the datasources' bearer and the encryption key in
the secret store, and a sidecar that keeps the controller's Viewer token.
The datasources reach the stores through the gateway with that bearer, and
Grafana's /metrics asks for the stores' kind of credential, which the vhost
sends. The five host units, the journal forwarder, its client glue and the
unix-socket directory go with the container.
This commit is contained in:
atlas 2026-11-27 22:51:25 +01:00
commit 9f62e71dae

View file

@ -124,6 +124,10 @@ starts on an empty cache on every start of the pod; an upgrade from the
container doesn't carry the old cache over. The whisper model isn't state: the
pod's image holds it.
`swarm-grafana` keeps its database in the claim
`swarm-grafana-store`, a static local volume on the directory its container kept
([the Grafana pod](#the-grafana-pod)).
`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers
already pushed. It sits in the PersistentVolumeClaim `swarm-ci-metrics-store`, mounted at
`/var/lib/private/swarm-ci-metrics`, which binds a static local volume on that
@ -525,6 +529,72 @@ pushes to the store and Grafana that reads it.
`agentAuthVerdictTtl` and the store identity files). The host collector reads
the pods' output from the node like any pod's.
## The Grafana pod
`swarm-grafana` is the swarm's Grafana: one Deployment with one replica and the
`Recreate` strategy. The vhost `grafana.<swarm domain>` stays on the host and
dials the pod's ClusterIP Service by name, as the stores' vhosts do, so
`gateway.dns.enable` has to be on.
- **The pod.** The module defines Grafana's `ExecStart`, and the image holds the
nixpkgs Grafana with the plugins `deploy.grafana.plugins` names, its
configuration file and its provisioning directory (datasources, dashboards and
alert rules), all read-only. A start script applies the stored administrator
password to the database with `grafana cli admin reset-admin-password`, because
the `admin_password` setting gives its password to a new database only,
and then runs `grafana server`. Grafana serves plain HTTP on port 3000,
pushes no telemetry and logs in to nothing itself: its output is the pod's log,
which the host collector reads like any pod's ([logs](telemetry.md#logs)). The
startup probe requests `/api/health` every ten seconds for up to five minutes,
which covers a database migration after an upgrade.
- **The init container.** `fetch-secrets` logs in to the secret store with the
pod's ServiceAccount token under the jwt role `swarm-grafana-oidc`, and writes
four files, mode 0400, to the pod's in-memory `runtime` volume: the OIDC client
secret, the administrator password, the bearer of the datasources and the
datasource encryption key. It reads the client secret from
`swarm/services/<client id>/oidc/client`, which authelia's mint stores, and
exits non-zero when the store holds none, so the pod waits in `Init` and retries
until the mint has written it. The other three it creates when the store holds
none (a lost race reads the winner's value) and never replaces.
- **Rotation.** Grafana reads the four files once, when it starts. A replaced
OIDC client secret, administrator password or bearer takes effect when the pod
restarts: `kubectl -n hyperhive rollout restart deployment/swarm-grafana`. No
`swarmctl` verb restarts it. The bearer is also read by the responders of both
stores, which pick up a replaced value within a minute.
- **The sidecar.** `controller-token` keeps `swarm-controller`'s Viewer service
account in Grafana and its token at
`swarm/controller/swarm-controller/grafana/token`. Every five minutes it calls
Grafana's API with the token it stored, and creates the account and a new
token when Grafana refuses it, as Grafana does after its database is
recreated. It reaches Grafana on the pod's loopback with the administrator
password.
- **The datasources.** Grafana dials `metrics.<swarm domain>` and
`logs.<swarm domain>` by name through the gateway and sends its bearer, which
the responders of those stores check. The pod holds no store's listener
credential: the only credential Secret it mounts is its own,
`swarm-grafana-credentials`. The cluster's DNS answers those names with the
bridge address, and the pod's policy allows port 443 of the host.
- **Who may use it.** The UI and the API need an OIDC session or the
administrator's basic auth, and the login form is off. `/api/health` is open
by Grafana's design. `/metrics` takes a credential of its own, set with
`[metrics] basic_auth_username` and `basic_auth_password` (the user
`swarm-store`, the password from the Secret `swarm-grafana-credentials`, which the unit of
[the stores' listener credential](#the-stores-listener-credential) creates at
`swarm/services/grafana/store-auth`). The vhost sends it after
authelia has checked the caller, so a request that reaches the pod without it
gets 401.
- **State.** Grafana's data directory on the host is
`/var/lib/nixos-containers/swarm-grafana/var/lib/grafana`: the claim
`swarm-grafana-store` binds a static local volume on it, so the database the
container kept is the pod's, with its dashboards, annotations and users. The
node label is `hyperhive.darkest.space/state-grafana`
([node labels](node.md#node-labels)), and the pod's `fsGroup` is `65532` with
the `OnRootMismatch` policy, as for the stores.
- **Who reaches what.** The namespace's `default-deny-ingress` and the pod's own
policy admit the node alone, which is the host's nginx and the kubelet's
probes. The pod reaches cluster DNS, the secret store's pod listener and port
443 of the host.
## The stores' listener credential
Each store listens on its pod's address behind a ClusterIP Service, and the
@ -544,6 +614,10 @@ every route but `/health` and the few built-in ones that answer a fixed text,
the import, delete and admin routes of the metrics store included. Root can
read the credentials, so treat the host as trusted for what root can do.
Grafana's `/metrics` route has a credential of the same kind, created by the same unit at
`swarm/services/grafana/store-auth` and sent by the vhost from
`/var/lib/swarm-store-auth/grafana.conf`: [the Grafana pod](#the-grafana-pod).
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits