Repository navigation
Description
Problem
After bumping the cloudflared image version and redeploying the stack, cloudflared logs showed persistent connection errors:
dial tcp 10.43.24.33:80: connect: connection refused
targeting originService=http://traefik.kube-system.svc.cluster.local:80, even though the Traefik pod, Service, and Endpoints were all healthy.
A second, unrelated bug was also found and fixed while investigating: the root k8s/kustomization.yaml was missing cloudflared from its resources: list, so devops k8s deploy-stack never actually applied changes to the cloudflared manifests (including the image bump that triggered this investigation).
Root Cause
This cluster's kube-router NetworkPolicy engine (embedded in k3s) fails to enforce egress rules that combine a peer selector (to:) with a ports: restriction in the same rule — the rule silently fails closed instead of allowing the traffic. This is direction-specific: the equivalent ingress pattern (from: + ports:) works correctly, and ports-only egress rules (no peer selector) also work correctly.
The cloudflared-isolation NetworkPolicy's Traefik egress rule combined a namespace/pod selector with ports: [80, 443], which silently failed to allow traffic, causing cloudflared to be unable to reach Traefik.
Confirmed live on the cluster via scratch NetworkPolicy tests and debug pods before applying the fix.
Fix
- Added
cloudflaredto the root kustomizationresources:list so its manifests are actually applied bydeploy-stack. - Removed the
ports: [80, 443]restriction from the Traefik egress rule ink8s/cloudflared/networkpolicy.yaml, keeping only the peer selector, with a comment explaining the kube-router limitation. - Verified live: NetworkPolicy re-applied, cloudflared deployment restarted, fresh logs show zero connection-refused errors; ingress to cloudflared metrics still restricted as expected (no regression).
- Added regression tests in
tests/test_k8s_cloudflared.py.
Verification
uv run ruff check/ruff format --check/pytest tests/test_k8s_cloudflared.py -vall pass.- Full
devops cipre-push quality gate passed. - Live cluster verification performed via kubectl against the affected cluster.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity