Skip to content

feat(k8s): devops k8s tunnel keeps the cloudflared forward to k8s.<domain> running, so the tunnel context works off the home network #1641

Description

@dan-petty

Friction

Off the home network, the tunnel kubeconfig context from #1595 works only while cloudflared access tcp runs in a terminal someone keeps open. When the listener isn't running, kubectl fails with "connection refused" on 127.0.0.1:16443. That is the same error the workstation gave before #1595, and nothing says the forward is what's missing. k8s/README.md leaves "a command that keeps the forward running" to its own item.

Evidence

  • On 2026-10-17, after v0.2.36 reached main and Argo CD synced cloudflared's 6443 egress rule:
    • With the listener running, kubectl --context <cluster>-tunnel get nodes listed the cluster's nodes through k8s.<domain>.
    • A second after the listener exited, the same command failed with "The connection to the server 127.0.0.1:16443 was refused".
  • A second listener started on the same port fails with "bind: address already in use". Nothing owns the forward, so the user starts and stops it by hand.
  • devops k8s commands use the kubeconfig's current context. Off the network, the user must also switch to the tunnel context by hand.

Remedy

A devops k8s tunnel command group.

devops k8s tunnel start:

  • runs cloudflared access tcp --hostname <host> --url 127.0.0.1:<port> detached, in its own process group (start_new_session=True);
  • records its PID under the data directory;
  • waits until the port accepts connections;
  • prints the Access login URL when cloudflared asks for one;
  • when a forward is already running, reports it instead of starting another;
  • with --context, adds or updates the <cluster>-tunnel context with the kubectl config commands k8s/README.md gives.

devops k8s tunnel stop:

  • signals the process group with the guarded os.killpg pattern AGENTS.md requires (never PID 0 or 1, never its own group).

devops k8s tunnel status:

  • reports whether the port is listening;
  • reports whether the API server answers (a 401 from /version counts as reached).

Configuration:

  • The hostname comes from a setting, with no fallback: when the setting is unset, the command fails with an error naming it.
  • The port defaults to a value in src/devops_cli/config/defaults.py.

Tests use a fake cloudflared in tmp_path that listens on a free port:

  • after start, status reports the port listening;
  • a second start starts no new process;
  • stop ends the whole process group;
  • an unset hostname fails with an error naming the setting.

Pending a person: from off the home network, devops k8s tunnel start --context, the Access login, then kubectl --context <cluster>-tunnel get nodes.

Proposed design

Problem statement

The current k8s tunneling setup requires manual intervention to keep the cloudflared forward running when off the home network. Users must manually start and stop cloudflared access tcp commands, which is error-prone and inconvenient.

Acceptance criteria

  • Criterion 1: A devops k8s tunnel start command exists that runs cloudflared in detached mode with its own process group
    Verification: Running devops k8s tunnel start creates a new process group and starts cloudflared with start_new_session=True
  • Criterion 2: The tunnel command records its PID under the data directory after starting
    Verification: After running devops k8s tunnel start, the PID is written to a file in the data directory
  • Criterion 3: A devops k8s tunnel stop command exists that properly terminates the tunnel process group
    Verification: Running devops k8s tunnel stop sends SIGTERM to the process group using os.killpg with proper guards
  • Criterion 4: A devops k8s tunnel status command reports whether the port is listening and the API server answers
    Verification: Running devops k8s tunnel status returns information about port listening status and API server reachability
  • Criterion 5: The tunnel command fails with an error when hostname setting is unset
    Verification: Running devops k8s tunnel start without a hostname setting reports an error naming the missing setting

Key questions

  • What is the default port for the tunnel?: The default port comes from src/devops_cli/config/defaults.py [sources: src/devops_cli/config/defaults.py]
  • How should the tunnel command handle an already running forward?: When a forward is already running, the command should report it instead of starting another (proposed)
  • What configuration setting provides the hostname for the tunnel?: The hostname comes from a setting with no fallback - when the setting is unset, the command fails with an error naming it (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/feature. The candidate proposes a new command group to manage k8s tunnels, which is a feature.
    • Priority: P2-Medium. This feature improves usability and workflow but isn't critical for core functionality.
    • Value: High. It solves a significant friction point for users working off the home network.
    • Effort: Medium. The implementation requires managing process groups, handling configuration, and writing tests with fake cloudflared.
  3. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at ae8c2d9 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  5. added a commit that references this issue on Oct 29, 2026
  6. removed
    status/ready
    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

    effort/mediumpriority/p2-mediumsource/agenttype/featurevalue/high

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions