infra(logging): Loki single-binary + Alloy DaemonSet, 192h bounded retention (F4)

No log store existed: pod logs were kubelet files on the node and died with the
pod (~8h deepest history for a busy workload). Adds:

- Loki 3.7.1 single-binary (1 Deployment + 8Gi local-path PVC on siriussec),
  retention_period 192h with the compactor deleting on filesystem, ingest rate
  limits, so the store is time- and rate-bounded.
- Alloy 1.13.0 DaemonSet (all nodes, no RBAC, no API access) shipping
  /var/log/pods, /var/log/journal and the Pi's docker json logs. File sources
  read from byte 0 and stamp the timestamp from the line, so the history the
  nodes already held (18d cilium on linode, 31d registry on rpi) landed on day
  one instead of starting the 7-day clock at deploy time.
- Grafana datasource (uid loki) via the existing sidecar, ServiceMonitor,
  ingest-rate guard rule.
- docs/logging.md with the measured bytes/day, the 8-day projection and the
  runbook.

Measured: ~360-502 MB/day raw -> ~90 MB/day compressed, 192h -> <=0.8GiB, on a
node with 103GiB free (house floor 32GiB). Verified 7-day-old lines return for
kube-system cilium-agent and for the siriussec/linode journals, and survive a
Loki pod restart (PVC).
This commit is contained in:
Lance Walters 2026-11-27 00:36:56 -05:00
commit 179257d8fb
10 changed files with 890 additions and 0 deletions

View file

@ -0,0 +1,194 @@
// Grafana Alloy — log collection for the house cluster.
//
// Three sources, and none of them touch the Kubernetes API (everything is read
// off the node's filesystem), so this DaemonSet needs ZERO RBAC beyond the
// default ServiceAccount:
//
// 1. kube/pods — /var/log/pods/<ns>_<pod>_<uid>/<container>/*.log
// 2. systemd-journal — /var/log/journal (kubelet, containerd, sshd, kernel)
// 3. docker/json — /var/lib/docker/containers/*/*-json.log (Pi-only
// services that are not pods: local image registry, Garage)
//
// `tail_from_end = false` on both file sources is deliberate: the nodes already
// hold history (pod log files reach back days; the linode's cilium-agent file
// reaches back 18 days, the Pi's registry json log 31 days). Ingesting those
// files from byte 0 is what gives the store real depth on day one instead of
// starting the 7-day clock at deploy time. The `timestamp` stages stamp every
// entry with the timestamp carried by the line itself rather than the ingest
// time — without that, backfill would land as "now" and be worthless.
//
// Positions live on a hostPath (/var/lib/alloy-data) so a pod restart resumes
// instead of re-shipping every byte.
logging {
level = "info"
format = "logfmt"
}
loki.write "local" {
endpoint {
url = "http://loki.logging.svc.cluster.local:3100/loki/api/v1/push"
}
external_labels = {
cluster = "homek8s",
}
}
// --------------------------------------------------------------- pod stdout
local.file_match "pod_logs" {
path_targets = [{ "__path__" = "/var/log/pods/*/*/*.log*" }]
sync_period = "15s"
}
discovery.relabel "pod_logs" {
targets = local.file_match.pod_logs.targets
rule {
source_labels = ["__path__"]
regex = "/var/log/pods/([^/]+)_([^_]+)_([^/]+)/([^/]+)/[^/]+"
target_label = "namespace"
replacement = "$1"
}
rule {
source_labels = ["__path__"]
regex = "/var/log/pods/([^/]+)_([^_]+)_([^/]+)/([^/]+)/[^/]+"
target_label = "pod"
replacement = "$2"
}
rule {
source_labels = ["__path__"]
regex = "/var/log/pods/([^/]+)_([^_]+)_([^/]+)/([^/]+)/[^/]+"
target_label = "container"
replacement = "$4"
}
rule {
target_label = "job"
replacement = "kube/pods"
}
rule {
target_label = "node"
replacement = sys.env("NODE_NAME")
}
}
loki.source.file "pod_logs" {
targets = discovery.relabel.pod_logs.output
forward_to = [loki.process.pod_logs.receiver]
tail_from_end = false
}
loki.process "pod_logs" {
// CRI format: "<RFC3339Nano> <stdout|stderr> <F|P> <message>"
stage.cri {}
stage.timestamp {
source = "time"
format = "RFC3339Nano"
}
stage.labels {
values = {
stream = "stream",
}
}
forward_to = [loki.write.local.receiver]
}
// ----------------------------------------------------------- systemd journal
loki.relabel "journal" {
forward_to = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
rule {
source_labels = ["__journal_priority_keyword"]
target_label = "level"
}
rule {
source_labels = ["__journal__hostname"]
target_label = "host"
}
rule {
target_label = "job"
replacement = "systemd-journal"
}
rule {
target_label = "node"
replacement = sys.env("NODE_NAME")
}
}
loki.source.journal "system" {
path = "/var/log/journal"
// 192h matches the store's retention: read the whole retained window once,
// then follow. The default is 7h, which would drop most of the history.
max_age = "192h"
relabel_rules = loki.relabel.journal.rules
forward_to = [loki.write.local.receiver]
}
// ------------------------------------------------- non-pod Docker containers
local.file_match "docker_logs" {
path_targets = [{ "__path__" = "/var/lib/docker/containers/*/*-json.log" }]
sync_period = "30s"
}
discovery.relabel "docker_logs" {
targets = local.file_match.docker_logs.targets
rule {
source_labels = ["__path__"]
regex = "/var/lib/docker/containers/([0-9a-f]{12})[0-9a-f]*/[^/]+-json\\.log"
target_label = "container_id"
replacement = "$1"
}
rule {
target_label = "job"
replacement = "docker/json"
}
rule {
target_label = "node"
replacement = sys.env("NODE_NAME")
}
}
loki.source.file "docker_logs" {
targets = discovery.relabel.docker_logs.output
forward_to = [loki.process.docker_logs.receiver]
tail_from_end = false
}
loki.process "docker_logs" {
stage.json {
expressions = {
log = "log",
time = "time",
}
}
stage.timestamp {
source = "time"
format = "RFC3339Nano"
}
stage.output {
source = "log"
}
forward_to = [loki.write.local.receiver]
}