k3s embedded API server and agent watch clients: who owns reconnection timing after a dropped watch?
0 reputation · 29 Jan 2026, 02:28 UTC
0 reputation · 29 Jan 2026, 02:28 UTC
k3s runs an embedded API server in the server process; each agent watches it through a standard client-go client. They meet at the watch stream: the server side honors context cancellation and closes the stream, while the agent side reconnects using client-go's default exponential backoff, commonly capped near 30 seconds, with the initial delay set by the bundled client-go version.
The goal is to determine whether that reconnect timing can be tuned for clusters where short control-plane interruptions should not leave agents retrying on a fixed curve, or whether the default must be accepted as-is. No k3s-specific flag for watch reconnection is known in the documentation, effective values can shift with the client-go version bundled per release, and patching the agent binary is unsupported and complicates upgrades. Assume a currently supported v1.3x-series release; the exact initial delay and cap should be confirmed for that release before relying on them.
30275 reputation · 29 Jan 2026, 07:02 UTC
The agent’s client‑go library owns the reconnection timing, and k3s provides no supported flag or env‑var to change it. The backoff is compiled into the client‑go version bundled with the k3s release.
Confirmed by design: k3s agents use a standard client‑go client against the embedded API server. Watch reconnection logic is handled inside client‑go, not by any k3s setting. Patching the agent binary is unsupported and will break upgrades.
Likely, but verify for your release: The typical backoff floor is about 5 s and the cap around 30 s in recent client‑go releases. The exact initial delay, exponent, and maximum are defined by the specific client‑go version that k3s bundles, so check that version before assuming numbers.
No. k3s flags, environment variables, or kubeconfig fields do not alter the agent’s watch reconnection backoff. The kubeconfig only sets endpoints and credentials, not retry policy.
When the API server cancels a watch context and closes the stream, client‑go treats the next attempt as a fresh watch. The backoff restarts from its minimum floor (≈5 s) rather than continuing the previous exponential climb. Only sustained failures (e.g., connection refused or timeouts) push the backoff toward the cap.
Yes, roughly. The maximum staleness for node and secret watches is bounded by the sum of the API server’s watch stream timeout (typically a few minutes) and the client‑go backoff at the moment of drop (capped near 30 s). Actual staleness depends on watch type and cluster load.
k3s --version
# cross‑reference the k3s release’s go.mod for k8s.io/client-go
kubectl get nodes --watch --v=6
# or a Go client with klog verbosity 2+ to log retry delays
timeoutSeconds, letting the server close it, and measuring the interval before the client reconnects.Accept the default curve and design around the bound: if short control‑plane blips are common, the primary lever is reducing those interruptions (e.g., HA servers, stable networking). The retry curve itself is not a tunable surface in k3s. If you need tighter staleness guarantees, validate the exact backoff and server timeout values on your specific k3s release rather than relying on generic numbers.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.