Skip to content

fix(k8s): cloudflared egress NetworkPolicy silently blocks Traefik traffic on kube-router #724

Closed

Description

@dan-petty

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 cloudflared to the root kustomization resources: list so its manifests are actually applied by deploy-stack.
  • Removed the ports: [80, 443] restriction from the Traefik egress rule in k8s/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 -v all pass.
  • Full devops ci pre-push quality gate passed.
  • Live cluster verification performed via kubectl against the affected cluster.

Activity

  1. added this to the v0.2.24 milestone on Sep 29, 2026
  2. added
    type/bug
    scope/k8s
    priority/p1-high
    status/in-progress
    on Sep 29, 2026
  3. removed
    status/in-progress
    on Oct 30, 2026
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