Skip to content

fix(k8s): pod logs reach loki once and labelled, with alloy as the only shipper (remove fluent-bit) #548

Closed

Description

@dan-petty

Problem Statement

fluent-bit's Kubernetes filter cannot reach the API server. Its pods log [filter:kubernetes:kubernetes.0] kube api upstream connection error every few seconds (checked on hog and condor, 2026-10-01). With no metadata, the namespace, pod and container labels on its Loki output (k8s/logging/fluent-bit-values.yaml:51) come out empty. In the hour before the check, {job="fluent-bit"} held two streams:

  • 180 lines labelled with one pod, default/gpu-feature-discovery-rdp5j;
  • 3,885 lines carrying only job and service_name.

Why the API server is unreachable. The kubernetes Service resolves to 192.168.1.4:6443, which is a node address. The logging policy's API rule (k8s/logging/networkpolicy.yaml:43-57) lists only namespaceSelector peers. Those match pod addresses, never a node's. #737 fixed the same gap for monitoring with an ipBlock peer (k8s/monitoring/networkpolicy.yaml:82-85, f93231b).

What changed after this item was filed (2026-09-24). #734 (fdd4d0f, 2026-09-30) turned on k8s-monitoring's pod log collection: podLogsViaLoki with the alloy-logs DaemonSet (k8s/monitoring/k8s-monitoring-values.yaml:76-78, 148-160). Alloy now ships every namespace's pod logs to the same Loki (lines 13-15). It sets namespace and container as stream labels and stores pod as structured metadata. Alloy reaches the API server through monitoring's ipBlock rule, and it pushes to Loki through monitoring's egress rule to logging on TCP 3100 (k8s/monitoring/networkpolicy.yaml:129-136). As a result:

  • Per-workload queries already work through Alloy's streams, for example {namespace="llm", container="litellm"}. The SRE Service dashboard already queries Loki by namespace, pod and container (k8s/monitoring/dashboards/sre-service.json), never by job="fluent-bit".
  • fluent-bit tails only default, llm and sandbox (fluent-bit-values.yaml:30), and Alloy ships all three. In the same hour fluent-bit sent 4,065 lines and Alloy 4,063 for those namespaces. So every line is stored twice, once without labels, on Loki's 2Gi volume (k8s/logging/loki-values.yaml:44-46). Loki deletes nothing by age: the values set retention_period: 720h (line 29), but no compactor block turns retention on (Metrics and logs are kept for two hours #550).
  • fluent-bit is the only pod in logging with hostPath volumes. That is why the namespace enforces privileged (k8s/namespaces.yaml:55-63; the reason is stated in tests/test_k8s.py:1250). It is also why the logging policy carries an API rule, and that rule doesn't work.

What changed again on 2026-10-01 (#922, 0778f60) and 2026-10-02 (#935, 85d3c19). The OpenTelemetry collector got an OTLP log exporter to Loki (k8s/otel/values.yaml:77-81, pipeline at 106-109), and the logging policy's ingress rule now admits otel beside monitoring on TCP 3100 (k8s/logging/networkpolicy.yaml:17-27). Two tests pin that rule: tests/test_k8s_logging_stack.py:214-227 and tests/test_k8s_monitoring_integration.py:284-301. The collector forwards application logs that clients send it over OTLP; it does not tail container files, so it is not a pod-log shipper. "Pod-log shipper" in this item means a component that reads /var/log/containers on the nodes and pushes those lines to Loki. After this item there is one: Alloy.

Fixing fluent-bit's egress would leave two pod-log shippers and keep every line duplicated. Removing fluent-bit leaves one shipper, which already labels its streams and already reaches the API server.

No alert can see this today. Prometheus holds no loki_*, fluentbit_* or Alloy loki_write_* series (checked 2026-10-01). A runtime alert needs #551's scrape and #549's receiver first, so it is split off (#890).

Proposed Solution

Alloy becomes the only component that ships pod logs to Loki. fluent-bit leaves the repository, together with everything that exists only because of it. A gate test pins the single-shipper setup and the egress Alloy depends on: the API server and the push to Loki.

  • Delete k8s/logging/fluent-bit-values.yaml.
  • src/devops_cli/commands/k8s/stack_lifecycle.py: remove the fluent repo (line 52) and the fluent-bit release (lines 137-142). The logging stack becomes Loki plus its NetworkPolicy (_MANIFESTS_BY_STACK["logging"], line 162, is unchanged).
  • src/devops_cli/config/constants.py:1899-1901: remove fluent-bit from CONST_HELM_DAEMONSET_RELEASES. Its only reader is stack_lifecycle.py:615; no test references the constant.
  • k8s/ingress/ingress-routes.yaml:388-410: remove the fluent-bit-ingress document (and the --- separator at line 387). No test references this file.
  • k8s/logging/networkpolicy.yaml: remove the API-server egress rule (lines 43-57: TCP 443, 6443 and 10250 to default and kube-system). No existing test pins that rule (tests/test_k8s_network_policies.py:13 leaves logging out of TARGET_NAMESPACES, and the logging-policy test at tests/test_k8s_logging_stack.py:180-238 makes no egress assertion). The comment at line 14 stops naming Fluent Bit. The ingress rule that admits monitoring and otel on TCP 3100 (lines 17-27) stays, because Alloy and the OTel collector push through it. Its comment (line 17) already says so.
  • k8s/namespaces.yaml:61: logging enforces baseline.
  • src/devops_cli/security/kubeconform.py:36-40 and tests/test_k8s_manifest_validation.py:32-38, 81-84: stop citing fluent-bit, and drop the now-false claim that exactly one values file declares kind alone. Remove fluent-bit-values.yaml from the parametrized list at lines 122-130. With the file gone, that case would pass without checking anything (the test loops over rglob matches and asserts nothing when there are none, lines 133-135).
  • Rewrite the tests that read fluent-bit values: tests/test_k8s_logging_stack.py:22-36 and 185-200, and tests/test_k8s.py:1180-1185, 1250-1257 and 1267-1276.
  • k8s/README.md: add a logging row to the stacks table (lines 7-11). It says the stack is Loki and that pod logs come from the infra stack's Alloy. The all row (line 11) lists the logging namespace.
  • changelog.d/548.md: the entry (house-style, under ### Removed and ### Changed), with the one-time cleanup commands from the "Pending a person" criterion.
  • docs/agent/tasks/task-548-logs-reach-loki-without-their-pod-or-namespace.md: rewritten to match, in the delivering pull request. It still says v0.2.24 and Backlog and describes the old fix-fluent-bit deliverable.

Scope

In scope: the files above, the three test files, the README row, the changelog fragment and the task file. One pull request.

Constraints:

Key Questions

  • Which component ships pod logs: fluent-bit or Alloy? Answered: Alloy. It already ships every namespace, with labels; it already reaches the API server; it is part of the monitoring chart the cluster runs anyway; fluent-bit's output duplicates it line for line in the three namespaces fluent-bit tails. Removing fluent-bit takes away a Helm release, the only hostPath DaemonSet in logging, and an API rule that doesn't work. Keeping fluent-bit instead would mean: an ipBlock peer on TCP 6443 in k8s/logging/networkpolicy.yaml:43-57 as fix(k8s): restore kubernetes cpu metrics and align monitoring dashboards to homelab-k3s #737 did for monitoring; podLogsViaLoki.enabled: false; and a gate test pinning fluent-bit's API egress instead of Alloy's.
  • Is the OTel collector's Loki exporter a second shipper that this item must remove? Answered: no. It forwards OTLP logs that applications send to the collector (k8s/otel/values.yaml:106-109); it reads no container files. It stays, with its ingress rule in the logging policy and the two tests that pin it.
  • Must pod be a stream label, as the original deliverable said? Answered: no. By default the chart stores pod as structured metadata. Pod names change on every rollout, and Loki's guidance keeps such values out of the index. Loki returns structured metadata merged into each result stream's label set unless the client asks for categorized labels, which devops k8s logs does not (src/devops_cli/k8s/logql.py:388-399 reads the stream map only; no categorize flag anywhere in src/devops_cli), so the command shows pod (src/devops_cli/commands/k8s/cluster_context.py:283-284). A per-pod query is {namespace="llm"} | pod="<name>". feat(telemetry): centralized loki logql streamer, prometheus sparklines & trace waterfalls (tab-telemetry) #691 builds on that.
  • Does the item still deliver "a check or alert"? Answered: the check, yes (acceptance criteria 2-4). It catches these configuration causes: a second shipper in the logging stack; Alloy's pod logs turned off, or sent to a different Loki; Alloy's API egress narrowed or removed; the push path between monitoring and logging closed on either side. A runtime alert needs Loki or Alloy metrics in Prometheus (Metrics for the rest of the platform #551) and a receiver (Alerts fire into nothing: no Alertmanager, and k3s false positives #549); both are in the backlog, so the alert is feat(k8s): alert when pod logs stop reaching loki #890.
  • Who removes the live fluent-bit release and its Ingress? Answered: a person, once, with the commands in the "Pending a person" criterion. teardown-stack only uninstalls releases that are still listed (stack_lifecycle.py:885-889, minus CONST_HELM_TEARDOWN_RETAINED_RELEASES, constants.py:1905-1907), so code can't reach this release after the change. Pre-1.0 rules out a migration shim. The changelog fragment carries the commands. Nothing deletes the old unlabelled stream: Loki has no compactor retention turned on, so it stays on disk until Metrics and logs are kept for two hours #550 turns retention on. It drops out of the last criterion's 10-minute window once fluent-bit stops.
  • Can logging drop from privileged to baseline? Answered: yes. fluent-bit is the only pod there with hostPath volumes. On 2026-10-01, loki-0 and the loki-canary pods used no hostPath volumes, privileged containers, hostNetwork or added capabilities. The namespace already warns and audits at baseline (namespaces.yaml:62-63). Pod Security checks pods only when they are admitted, and a redeploy that recreates no pods proves nothing, so the "Pending a person" criterion checks with a server-side dry run of the label, after fluent-bit is gone and before the label changes. monitoring, where alloy-logs mounts the node's log directory, stays privileged (namespaces.yaml:20).
  • Does the logging NetworkPolicy still need an API-server rule? Answered: no. Loki's rules sidecar is off (loki-values.yaml:66-69), and the canary pushes straight to Loki (-push=true, the chart default seen on the live DaemonSet). Nothing left in logging calls the API.
  • Does deploy-stack --stack logging still produce logs on its own? Answered: no, by design. It deploys Loki. The infra stack's k8s-monitoring ships logs into Loki, as it already does today, and --stack all deploys both (VALID_STACKS, stack_lifecycle.py:166). The new README row says so.
  • Does devops k8s doctor (feat(k8s): cluster deployment health diagnosis (devops k8s doctor) #408) read these Loki streams? Answered: no. The owner fixed feat(k8s): cluster deployment health diagnosis (devops k8s doctor) #408's data source as the Kubernetes API only, so feat(k8s): cluster deployment health diagnosis (devops k8s doctor) #408 neither depends on this item nor is affected by it.

No key question is open.

Acceptance Criteria

  • No fluent-bit remains in code, manifests or tests. Verified by git grep -n -i fluent -- src k8s tests printing nothing (today it prints 29 lines across 9 files, 4 of them in the values file itself).
  • A test in tests/test_k8s_logging_stack.py asserts one structural tuple containing: the logging stack's release names, ("loki",); its Helm repo names, ("grafana",); podLogsViaLoki.enabled, which is True (k8s/monitoring/k8s-monitoring-values.yaml:76-77); the localLoki URL, http://loki.logging.svc.cluster.local:3100/loki/api/v1/push (line 15). Verified by the test passing.
  • A test asserts, as one structural tuple, two egress rules in k8s/monitoring/networkpolicy.yaml: TCP 6443 to an ipBlock of 0.0.0.0/0 except 169.254.169.254/32 (rule at lines 74-96, ipBlock at 82-85; this is the path Alloy's pod discovery uses, and the gap that broke fluent-bit); and TCP 3100 to the logging namespace (lines 129-136; the path Alloy pushes through). Verified by the test passing, and by a one-time manual mutation in review: deleting the ipBlock at lines 82-85 must make the test fail, and so must deleting the rule at lines 129-136. The test must keep passing when feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083 adds its egress rule to namespace devops in the same file, so it matches the two rules by content, not by index or rule count.
  • The updated logging-policy test (tests/test_k8s_logging_stack.py:180-238) checks both directions. Egress must be exactly the intra-namespace rule and the DNS rule (UDP 53 and TCP 53 to kube-system, lines 30-42 of the policy). Ingress must still admit monitoring and otel on TCP 3100, as the existing assertion at lines 214-227 does. The namespace test (tests/test_k8s.py:1250-1257) asserts that logging enforces baseline, and warns and audits at baseline. Verified by uv run pytest tests/test_k8s_logging_stack.py tests/test_k8s.py tests/test_k8s_manifest_validation.py tests/test_k8s_monitoring_integration.py.
  • The new tests replace the fluent-bit assertions they remove, and each test's call phase runs in under 1 s. Verified by uv run pytest tests/test_k8s_logging_stack.py --durations=10 showing no call row at or above 1 s, and by uv run devops ci passing within its 5-minute budget.
  • changelog.d/548.md exists and carries the one-time commands from the next criterion; CHANGELOG.md and docs/ROADMAP.md are untouched. Verified by git diff --stat release/v0.2.26 -- CHANGELOG.md docs/ROADMAP.md printing nothing (against release/v0.2.28 instead if the v0.2.25 cut moves this item there) and uv run devops pr check-readiness passing.
  • Pending a person, on homelab-k3s after merge:
    helm uninstall fluent-bit -n logging --kube-context homelab-k3s --wait
    kubectl --context homelab-k3s delete ingress fluent-bit-ingress -n logging
    kubectl --context homelab-k3s label --dry-run=server --overwrite ns logging pod-security.kubernetes.io/enforce=baseline
    uv run devops k8s deploy-stack --stack logging --context homelab-k3s
    kubectl --context homelab-k3s get pods -n logging
    kubectl --context homelab-k3s get ns logging --show-labels
    kubectl --context homelab-k3s get networkpolicy logging-default-perimeter -n logging -o jsonpath='{.spec.egress[*].ports[*].port}'
    
    Expected: the server-side dry run prints namespace/logging labeled (server dry run) and no warning that existing pods violate the new PodSecurity enforce level; only loki-0 and loki-canary-* pods, all Running and Ready; pod-security.kubernetes.io/enforce=baseline on the namespace; 53 53 as the policy's egress ports.
  • Pending a person, 15 minutes after the previous step, with kubectl --context homelab-k3s port-forward -n logging svc/loki 3100:3100 running in another terminal:
    curl -s -G http://localhost:3100/loki/api/v1/series \
      --data-urlencode 'match[]={job=~".+", source!="kubernetes-events"}' \
      --data-urlencode "start=$(date -d '-10 min' +%s)" \
      | jq '[([.data[] | select(.namespace == null or .container == null)]), ([.data[] | select(.namespace == "llm")] | length > 0)]'
    uv run devops k8s logs '{namespace="llm", container="litellm"}' --loki-url http://localhost:3100 --since 10m --limit 5 --format json
    
    Expected: the first command prints [[],true]: no unlabelled pod-log stream, and llm logs are still arriving. The first element lists any leftover stream with its labels, so a leftover can be told apart. On 2026-10-01 the equivalent count printed [1,true]; the 1 was the fluent-bit stream. A stream from the OTel collector's OTLP exporter (fix(k8s): grafana k8s-monitoring missing metrics, sre service dashboard and otel loki exporter #922) is not a pod-log stream and does not fail this criterion. The second command prints JSON with "source": "loki" and at least one entry, and every entry's stream carries namespace, container and pod.

Out of Scope

Dependencies

Monitoring cleanup amendment (2026-10-03)

Measured again on 2026-10-03. Over 24h, {job="fluent-bit"} stored 123.6 MB and 574k lines:

  • 534,211 lines carried no namespace label;
  • 38,594 llm lines and 1,407 default lines were labelled.

For comparison, Alloy shipped llm/ollama at 44.9 MB (516,869 lines) and llm/litellm at 2.2 MB (32,269 lines). fluent-bit's own stdout (job="logging/fluent-bit") added 11.8 MB and 115,834 lines, nearly all [filter:kubernetes:kubernetes.0] kube api upstream connection error. In the last hour there were 3,837 unlabelled lines, sampled as Ollama [GIN] access lines carrying only {job, service_name="fluent-bit"}. Helm release fluent-bit is at revision 67, and its DaemonSet is 4/4.

Criterion change. In the first "Pending a person" criterion, "only loki-0 and loki-canary-* pods, all Running and Ready" now reads "only loki-0, plus loki-canary-* pods if #1133 (Loki canary disabled) has not merged yet, all Running and Ready". This lets the two items merge in either order.

Grouping. This item is a child of #1128 (monitoring cleanup), in its first step. Its scope and placement are unchanged.

Activity

  1. added this to the v0.2.24 milestone on Sep 24, 2026
  2. added
    type/bug
    scope/k8s
    priority/p1-high
    on Sep 24, 2026
  3. modified the milestones: v0.2.24, v0.2.25 on Sep 30, 2026
  4. modified the milestones: v0.2.25, v0.2.26 on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to make room for the seven P1 items left open in the shipped v0.2.23, which were committed earlier. The roadmap-job items placed in v0.2.25 stay, and this item is among the oldest of the rest.

  6. changed the title [-]Logs reach Loki without their pod or namespace[/-] [+]fix(k8s): pod logs reach loki once and labelled, with alloy as the only shipper (remove fluent-bit)[/+] on Oct 1, 2026
  7. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    The devops-namespace egress rule and the README section now come from #1083 (split from #741). If #755 (v0.2.27) lands first, this item also deletes its fluent-bit Application.

  8. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1169, merged into release/v0.2.26.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  9. added a commit that references this issue on Oct 4, 2026
  10. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    The post-merge "Pending a person" step was finally done on 2026-10-08, four days after this item closed. Until then, the Fluent Bit release kept running four pods that sent a second copy of the tailed namespaces to Loki. It was removed by an agent after a dry run, with the owner's go-ahead:

    helm -n logging uninstall fluent-bit        # DaemonSet, ConfigMap, Service, ServiceAccount, ClusterRole, ClusterRoleBinding, release history
    kubectl -n logging delete ingress fluent-bit-ingress
    

    Argo CD's OrphanedResourceWarning on the logging and loki Applications (17 objects) cleared on the next refresh. In the same pass, Secret/cloudflared/cloudflared-tunnel-token was also deleted. It is an older copy of the tunnel token that no workload referenced; the cloudflared Deployment reads cloudflared-token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/k8stype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions