8000 k3s: Let pods reach the kubelet with the bundled network by andsens · Pull Request #31 · nixos-homelab/shared · GitHub
[go: up one dir, main page]

Skip to content

k3s: Let pods reach the kubelet with the bundled network - #31

Merged
andsens merged 1 commit into
mainfrom
k3s-metrics-flake
Nov 19, 2026
Merged

andsens merged 1 commit into
mainfrom
k3s-metrics-flake

Conversation

@andsens
@andsens andsens commented Nov 19, 2026
Copy link
Copy Markdown
Collaborator

checks.k3s has failed now and then at the metrics-server subtest since 2026-11-15. This is the cause and the fix.

What the failing runs show

Three CI attempts failed at this subtest (runs 43767292207, 44390246564 and 44590951510, all on attempt 1). They all look the same: every metrics-server scrape of the kubelet times out, for the whole 300 s:

scraper.go:147] "Failed to scrape node, timeout to access kubelet" err="Get \"https://192.168.1.1:10250/metrics/resource\": context deadline exceeded"

The APIService stays MissingEndpoints because the pod never gets Ready. In none of the three does k3s log Starting network policy controller. Passing runs log it 2–3 s after the kubelet starts.

Why

  • With the bundled network, kube-router's network policy controller is what lets pod traffic to the node through. It adds KUBE-ROUTER-INPUT at the top of INPUT, and that chain accepts traffic from pods that comply with policy. The NixOS firewall comes after it and only opens 6443. A local dump from a passing run shows metrics-server's packets going through its KUBE-ROUTER-INPUT pod chain.
  • k3s starts that controller after flannel (pkg/agent/netpol/netpol.go at v1.35.8+k3s1). Before starting, it waits for the node's Ready condition to carry a heartbeat no older than startTime := time.Now().Truncate(time.Second). If the kubelet posted Ready in an earlier second, k3s waits for the next status post. Once the node has settled, the kubelet only posts at nodeStatusReportFrequency, which defaults to 5m. That is past the subtest's 300 s.
  • The logs line up with this on the second. The table compares kubelet's Fast updating node status as it just became ready with flannel's lines just before netpol.Run:
run Ready posted flannel netpol started
44046696278 (pass) 08:30:03.438 08:30:03 yes
43769271952 (pass) 22:31:38.679 22:31:38 yes
43762021909 (pass) 21:13:09.562 21:13:09 yes
44590951510 (fail) 18:48:52.927 18:48:53 (eth1 picked) no
44390246564 (fail) 20:27:31.856 20:27:32 no
43767292207 (fail) 22:10:41.894 22:10:43 (node lease) no

So the runner isn't just slow. The scrapes are dropped for a full 5 minutes whenever that one-second race goes the wrong way.

Fix

When bundledNetworking is on, open 10250 on cni0. That lets pods reach the kubelet no matter when the controller starts. Once the controller is up, its rule accepts this traffic before the firewall sees it anyway, so the steady state doesn't change.

Verified locally

  • Netpol forced off (--disable-network-policy) with refused-connection logging on. Without the fix, metrics-server never gets Ready and the kernel logs refused connection: IN=cni0 … SRC=10.42.0.4 DST=192.168.1.1 … DPT=10250. With the fix it is Ready.
  • checks.k3s with the fix, 5 runs: the metrics subtest passed in all 5. In one of them (rep 3) the race hit and netpol never started. The metrics subtest still passed, in 21 s.
  • Reps 3 and 4 then failed at the prune subtest (owner-name of kube-apiserver-kubelet-admin never became prune-test). That is a different flake and so are the three other failed CI attempts since 2026-11-15. Each time, k3s's deploy controller re-applied every manifest in name order just as the test linked prune-test.yaml in, and rolebindings.yaml was applied right after it and took the binding back. It is not touched here.

Open decision

10250 only, or trust cni0 entirely. Trusting it would match what k3s allows once netpol runs (pods reach every node port unless an egress policy says otherwise). It would also cover pod→node traffic other than the kubelet during the startup window. I went with the narrower rule.

🤖 Generated with Claude Code

checks.k3s failed now and then at the metrics-server subtest (3 of the 7 failed CI attempts since
2026-11-15): every scrape of the kubelet at 192.168.1.1:10250 timed out, so metrics-server never
got Ready. In all three runs k3s never logged "Starting network policy controller", which it does
2-3 s after the kubelet in passing runs.

With the bundled network, the rule that lets pod traffic to the node in ahead of the NixOS
firewall comes from that controller (KUBE-ROUTER-INPUT). k3s starts it once the Ready condition of
the node carries a heartbeat no older than the controller's start, truncated to the second. When
the kubelet posts Ready in the second before, the next heartbeat comes with the kubelet's periodic
status report, 5 minutes on, past the subtest's 300 s. The firewall only opens 6443, so it drops
the scrapes until then.

Opens 10250 on cni0 when bundledNetworking is on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andsens
andsens merged commit 7bd3dd9 into main Nov 19, 2026
2 checks passed
@andsens
andsens deleted the k3s-metrics-flake branch November 19, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0