Expand description
Kubernetes port-forward over SPDY
Speaks SPDY/3.1+portforward.k8s.io (tunnelled inside WebSocket
binary messages) by default, falling back to the legacy Upgrade: SPDY/3.1 path when the apiserver rejects the WebSocket subprotocol.
Multiplexes many concurrent local TCP connections over a small pool of
upgraded connections using the SPDY/3.1 frame format.
§Why not kube::Api::portforward?
kube::Api::portforward opens a new WebSocket upgrade for every stream
pair, has no keepalive, and gives you opaque errors. This crate
multiplexes many stream pairs per upgrade, runs a Ping/Pong watchdog,
exposes structured thiserror errors, and gracefully falls back to the
legacy SPDY/3.1 path when the apiserver is too old for KEP-4006.
§Quick Start
use kube_portforward::Client;
use tokio::io::AsyncWriteExt;
let client = Client::new(kube, url);
let session = client.session("default", "nginx", 80).open().await?;
let mut stream = session.connect().await?;
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;
session.close().await?;Structs§
- Client
- entry point that bundles a
kube::Clientwith its cluster URL. - Client
Builder - Data
Stream - Error
Stream - Forwarder
- Long-lived port-forward orchestrator. Construct via
Forwarder::builder. - Forwarder
Builder - PodWatcher
- Watches pods in a namespace and tracks the currently ready pod matching
a
PodSelector. Owns a background reflector task that’s aborted onPodWatcher::shutdown. - Ready
Pod - Snapshot of the currently ready pod.
- Session
- One port forward session that multiplexes many concurrent local connections over a pool of upgraded connections to the apiserver.
- Session
Builder - Builder for opening a session
- Stream
- port forward stream backed by one stream pair on
a multiplexed connection to the apiserver. Implements
AsyncRead + AsyncWriteon the data half. Dropping theStream(or callingpoll_shutdown) sends a SPDY FIN frame so the apiserver tears down the backing pod connection right away.
Enums§
- Error
- PodChange
- Pod lifecycle change sent to subscribers.
- PodSelector
- Pod selection strategy.
- Recovery
Signal - Subprotocol
- Protocol negotiated for a port-forward session.