Introducing a new way to review your PRs.

Read the announcement

hcavarsan / kftray

kubectl port-forward manager and reverse tunnel (ngrok-like) for exposing local services publicly, with TLS termination, HTTP traffic inspection, UDP forwarding, multi-hop proxy routing through k8s clusters, stateful config via filesystem or git - GUI and TUI available

View on GitHub

19 documents · Updated Nov 23, 2026

docs / endpoint-exposure

Endpoint exposure and TLS

Endpoint exposure makes a service that normally runs on a local machine reachable through a Kubernetes cluster or a public domain. It joins a cluster relay, a short-lived tunnel, and an optional TLS boundary so traffic can reach the local service without moving that service into the cluster.

This page extends connection forwarding. For the other forwarding paths, see Kubernetes port forwarding and SSH forwarding.

Exposure model

An expose configuration publishes the local service through Kubernetes. The local port and address remain the final destination. Kubernetes resources provide the path that other clients use to reach them.

flowchart LR
    C[External client] --> E[Ingress or cluster Service]
    E --> R[Expose relay pod]
    R --> W[WebSocket tunnel]
    W --> K[Kubernetes port-forward]
    K --> L[Local service]

The relay carries HTTP by default. A cluster-only exposure can carry raw TCP when its protocol is set to TCP. Public exposure uses HTTP through an Ingress, so it does not support the raw TCP mode.

References: crates/…/mod.rs• L221-231 crates/…/config_model.rs• L202-207 crates/…/config.rs• L422-453

Exposure modes

The exposure type selects the boundary where traffic enters the cluster. Both modes use the same relay and tunnel, but they serve different audiences.

Cluster-only exposure

Cluster-only exposure creates a Kubernetes Service for callers inside the cluster. It is suited to internal access through cluster DNS and can carry either HTTP or raw TCP traffic.

The local service address and port define where the relay sends traffic after the tunnel reaches the workstation. The exposure_protocol value controls whether the relay treats that traffic as HTTP requests or as byte streams.

References: frontend/…/ExposeFields.tsx• L12-19 crates/…/kubernetes.rs• L217-247 examples/expose-internal.json• L1-12

Public exposure

Public exposure adds a Kubernetes Ingress in front of the Service. The alias becomes the public domain, and the Ingress controller becomes the internet-facing entry point.

Public exposure always uses HTTP. The alias is required because it names the Ingress host. The Ingress class and extra annotations let the cluster choose its routing rules without changing the tunnel to the local service.

References: frontend/…/ExposeFields.tsx• L39-74 crates/…/kubernetes.rs• L232-247 crates/…/kubernetes.rs• L957-1000 examples/expose-public.json• L1-17

Exposure lifecycle

Starting an exposure first prepares the relay resources, then connects the local side. The application reports the exposure as active only after the port-forward and reverse WebSocket tunnel are ready.

The startup path records the resources that belong to the attempt before creation begins. If startup is cancelled or a later connection step fails, it rolls back that attempt and keeps cleanup available until the cluster resources are removed. This prevents an Ingress or Service from pointing to a relay with no local destination.

When the exposure stops, the application closes the local tunnel and removes the Kubernetes resources that belong to that exposure. The same cleanup path also runs when the reverse tunnel exhausts its reconnect budget, so the UI does not keep showing a healthy endpoint with no working path behind it.

sequenceDiagram
    participant App as kftray app
    participant K8s as Kubernetes API
    participant Relay as Relay pod
    participant Local as Local service
    participant Client as Cluster or public client

    App->>K8s: Create relay Deployment and Service
    K8s-->>App: Relay pod ready
    App->>K8s: Port-forward relay listener
    App->>Relay: Open WebSocket tunnel
    Relay->>Local: Connect to local address and port
    Client->>Relay: HTTP request or TCP stream
    Relay->>Local: Forward traffic through tunnel
    Local-->>Client: Return response or bytes

The reverse tunnel retries connection failures with backoff. A connection that becomes ready resets the retry count. A permanent handshake rejection or an exhausted retry budget fails startup or stops the exposure instead of leaving readiness unresolved.

References: crates/…/mod.rs• L83-151 crates/…/mod.rs• L168-331 crates/…/websocket_client.rs• L222-335

Tunnel traffic

The reverse tunnel carries each HTTP request to the configured local address and returns its status, headers, and body to the relay. It also supports upgraded HTTP connections and raw TCP streams, so long-lived application protocols can use the same exposure path.

HTTP requests can use optional per-exposure logging. The tunnel refreshes the log policy while it runs, but raw TCP traffic does not use HTTP logging.

References: crates/…/websocket_client.rs• L96-219 crates/…/websocket_client.rs• L337-509 crates/…/websocket_client.rs• L511-681 crates/…/websocket_client.rs• L704-787

TLS boundaries

The repository has two separate TLS concerns. Public exposure uses Kubernetes certificate management for the public domain. The application SSL setting protects local forwarded endpoints that use domain aliases. Enabling one does not replace the other.

Public Ingress TLS

Public exposure can ask cert-manager to issue a certificate for the Ingress host. The expose configuration supplies the issuer name and issuer kind. The Ingress then names the TLS secret that cert-manager manages.

This certificate terminates HTTPS at the cluster Ingress. Traffic from the Ingress to the relay follows the cluster's routing setup, while the relay still uses its WebSocket tunnel to reach the local service.

References: frontend/…/ExposeFields.tsx• L119-174 crates/…/templates.rs• L64-107 crates/…/templates.rs• L118-130 crates/…/kubernetes.rs• L963-1000

Local forwarded-endpoint TLS

The application SSL setting provides HTTPS for forwarded endpoints with domain aliases. It creates a local certificate set from a kftray certificate authority, stores the private key in the system key store, and can add the authority to the system trust store.

The certificate covers the aliases known to the saved configurations. When SSL is enabled or disabled, running HTTPS forwards restart so their listeners use the new TLS state. Certificate validity is configurable, and certificates are renewed when they expire or no longer cover the current aliases.

References: crates/…/ssl.rs• L29-165 crates/…/cert_manager.rs• L55-85 crates/…/cert_manager.rs• L653-716 crates/…/start.rs• L95-123 frontend/…/SslSettings.tsx• L39-76

TLS trust

The local certificate authority must be trusted by the client that opens the HTTPS endpoint. The application can install it automatically when SSL is enabled, but installation can fail because the host trust store needs permission or user action.

Disabling local SSL removes the stored certificates, authority data, and system trust entry when cleanup permits. Public cert-manager certificates remain Kubernetes resources and follow the public exposure lifecycle instead.

References: crates/…/ssl.rs• L112-160 crates/…/cert_manager.rs• L191-257 crates/…/cert_manager.rs• L477-599 frontend/…/useSettingsSave.ts• L165-174

Configuration boundaries

Expose fields describe how a local service is published. TLS fields only apply at their matching boundary.

ConcernConfigurationResult
Audienceexposure_typeCluster-only Service or public Ingress
Local targetlocal_address, local_portDestination on the workstation
Cluster protocolexposure_protocolHTTP or raw TCP for cluster-only exposure
Public certificatecert_manager_enabled, cert_issuer, cert_issuer_kindcert-manager annotations and Ingress TLS
Public routingingress_class, ingress_annotationsIngress controller and extra routing rules
Local HTTPSSSL settingsLocal listener certificates and trust setup

The configuration rules keep public exposure on HTTP and require an alias and local port for every expose entry. The UI applies the same boundary rules by hiding cluster protocol choices for public exposure and showing certificate fields only for public exposure.

References: crates/…/config_model.rs• L135-157 crates/…/config.rs• L422-453 frontend/…/ExposeFields.tsx• L75-197 frontend/…/utils.ts• L98-114

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the public exposure rule aligned across the UI, config validation, and relay protocol. Public TCP would bypass the Ingress assumptions.
  • Keep the Ingress host, TLS host list, and certificate issuer annotations aligned. A mismatch can create an HTTPS route with no usable certificate.
  • Keep relay protocol negotiation aligned between the app and server. The TCP path requires the relay mode response before startup can succeed.
  • Keep local SSL setting changes coupled to forward restart behavior. A saved certificate state is not active on an already running listener until it restarts.
  • Keep expose cleanup aware of public resources when an exposure changes from public to cluster-only. The old Ingress must not remain as an unintended public route.
  • Keep startup cancellation and tunnel failure on the same cleanup path. A failed readiness signal must not leave a relay, port-forward, or public route behind.
  • Keep HTTP log policy refresh limited to HTTP exposure traffic. Raw TCP has no HTTP request or response records to update.

Important failure modes

TriggerConsequenceGuard
Public exposure has no aliasThe public Ingress cannot name its hostExpose validation requires an alias or domain
Public exposure selects TCPThe exposure cannot use the HTTP Ingress pathConfig validation rejects TCP unless the exposure is cluster-only
cert-manager issuer is missing or unavailableThe Ingress may have no trusted HTTPS certificatePublic TLS fields require an issuer; cert-manager must be present in the cluster
Relay does not support TCP modeA cluster TCP exposure cannot startThe client checks the relay mode handshake and reports the incompatible relay
Local CA installation lacks permissionHTTPS may work only with manual trust setup, or the SSL save reports an errorCA installation is attempted separately and its failure is surfaced
Reverse tunnel readiness times out or its retry budget is exhaustedStartup fails or the expose process stops and its endpoint is cleaned upReadiness has a timeout, and the tunnel reports terminal failure to the exposure lifecycle
Startup is cancelled during resource creation or connection setupA partial exposure can remain if cleanup is not completedThe lifecycle tracks the attempt and retries cleanup until its owned resources are removed

Key files

FileWhy to read it
crates/…/mod.rsShows the expose startup, resource ownership, tunnel readiness, active state, and stop boundary
crates/…/kubernetes.rsShows the cluster resources and the public-versus-cluster exposure split
crates/…/templates.rsShows how public Ingress annotations and TLS settings are formed
crates/…/websocket_client.rsShows how relay HTTP requests, upgrades, and TCP streams reach the local service
crates/…/reverse_http.rsShows how the relay accepts external HTTP or TCP traffic
crates/…/cert_manager.rsShows the local certificate lifecycle and trust-store flow
crates/…/start.rsShows when local forwarded listeners receive a TLS acceptor
crates/…/ssl.rsShows the application-facing SSL settings and restart behavior
frontend/…/ExposeFields.tsxShows the user-facing exposure and public TLS choices
frontend/…/SslSettings.tsxShows the user-facing local SSL controls