Skip to content

Commit a34e69d

Browse files
committed
KEP-5695: addressing comments by reviewers
1 parent 3799c78 commit a34e69d

File tree

1 file changed

+41
-15
lines changed
  • keps/sig-cli/5695-kubectl-reverse-port-forward

1 file changed

+41
-15
lines changed

keps/sig-cli/5695-kubectl-reverse-port-forward/README.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [Proposal](#proposal)
1010
- [User Stories](#user-stories)
1111
- [Story 1: Local Development with Remote Debugging](#story-1-local-development-with-remote-debugging)
12-
- [Story 2: Testing Webhooks in Development](#story-2-testing-webhooks-in-development)
12+
- [Story 2: Testing Sidecar Proxy with Local Policy Service](#story-2-testing-sidecar-proxy-with-local-policy-service)
1313
- [Story 3: Database Migration from Local Tools](#story-3-database-migration-from-local-tools)
1414
- [Notes/Constraints/Caveats](#notesconstraintscaveats)
1515
- [Risks and Mitigations](#risks-and-mitigations)
@@ -107,9 +107,15 @@ These workarounds add complexity, security concerns, and maintenance overhead. A
107107
Add a new flag `--reverse` (or `-R`) to the `kubectl port-forward` command that reverses the direction of the port forwarding. When this flag is used, kubectl will:
108108

109109
1. Establish a connection to the kubelet running the target pod
110-
2. Create a listener in the pod's network namespace on the specified remote port
111-
3. Forward incoming connections from that port back to kubectl
112-
4. kubectl will then forward these connections to the specified local port
110+
2. kubelet coordinates with the container runtime (containerd/cri-o) via CRI streaming API
111+
3. The container runtime creates a listener in the pod's network namespace on the specified remote port
112+
4. Forward incoming connections from that port back through the runtime → kubelet → kubectl
113+
5. kubectl then forwards these connections to the specified local port
114+
115+
**Note**: This involves changes across multiple layers:
116+
- kubectl: Connection handling and local port forwarding
117+
- kubelet: Reverse mode protocol support in the port-forward API
118+
- Container runtime (containerd/cri-o): Network namespace listener creation and stream multiplexing
113119

114120
### User Stories
115121

@@ -125,22 +131,24 @@ python -m http.server 8080
125131
# In another terminal, expose it to the pod
126132
kubectl port-forward --reverse mypod 8080:8080
127133

128-
# Now the pod can access http://localhost:8080 which goes to my local machine
134+
# Now applications in the pod can connect to localhost:8080
135+
# Those connections get tunneled back to your local machine's port 8080
129136
```
130137

131-
#### Story 2: Testing Webhooks in Development
138+
#### Story 2: Testing Sidecar Proxy with Local Policy Service
132139

133-
As a developer working on a Kubernetes admission webhook, I want my webhook running locally to receive requests from the API server running in my development cluster, so that I can rapidly iterate on webhook logic without repeatedly building and deploying container images.
140+
As a developer working on a service mesh configuration, I want my application pod's sidecar proxy to call my locally running policy/auth service, so that I can test authorization rules without deploying them to the cluster.
134141

135142
**Example:**
136143
```bash
137-
# Run webhook locally
138-
./my-webhook --port 9443
144+
# Run local policy service
145+
./policy-server --port 8181
139146

140-
# Expose it to the API server pod
141-
kubectl port-forward --reverse -n kube-system api-server-pod 9443:9443
147+
# Expose it to the sidecar proxy
148+
kubectl port-forward --reverse mypod 8181:8181
142149

143-
# Now the API server can call https://localhost:9443 for webhook validation
150+
# Now the sidecar proxy can call http://localhost:8181 for policy decisions
151+
# while the main application container continues to run in the cluster
144152
```
145153

146154
#### Story 3: Database Migration from Local Tools
@@ -219,7 +227,7 @@ The implementation builds upon the existing port-forward infrastructure with the
219227

220228
**2. Kubelet Changes** (`pkg/kubelet/`):
221229
- Extend PortForward API to support reverse mode
222-
- Implement pod network namespace listener creation using `socat` or native Go listeners
230+
- Implement pod network namespace listener creation using native Go listeners
223231
- Handle incoming pod connections and stream them to kubectl
224232
- Clean up listeners when kubectl disconnects
225233

@@ -229,7 +237,25 @@ The implementation builds upon the existing port-forward infrastructure with the
229237
- Connection establishment notifications (pod → kubectl direction)
230238
- Bidirectional data streams
231239

232-
**4. Flow Diagram:**
240+
**4. Container Runtime Changes** (External repositories):
241+
242+
Changes required in container runtimes to support reverse port-forwarding:
243+
244+
**containerd** (`containerd/containerd`):
245+
- Modify streaming server ([`internal/cri/streamingserver/server.go`](https://github.com/containerd/containerd/blob/main/internal/cri/streamingserver/server.go))
246+
- Add reverse port-forward handler endpoint
247+
- Implement network namespace listener creation
248+
- Handle bidirectional streaming for reverse connections
249+
250+
**cri-o** (`cri-o/cri-o`):
251+
- Modify port forward implementation ([`server/container_portforward.go`](https://github.com/cri-o/cri-o/blob/main/server/container_portforward.go))
252+
- Add reverse mode support to port forward handler
253+
- Implement listener in container network namespace
254+
- Stream reverse connections back to kubelet
255+
256+
**Note**: This KEP requires coordinated changes across multiple projects (kubernetes, containerd, cri-o). Implementation will need agreement and collaboration from runtime maintainers.
257+
258+
**5. Flow Diagram:**
233259

234260
```mermaid
235261
sequenceDiagram
@@ -260,7 +286,7 @@ sequenceDiagram
260286
kubectl->>User: Deliver response
261287
```
262288

263-
**5. Implementation Components:**
289+
**6. Implementation Components:**
264290

265291
- **Port Listener**: Create a TCP listener in the pod's network namespace
266292
- Native Go implementation using a Go network namespace library (such as [vishvananda/netns](https://github.com/vishvananda/netns)).

0 commit comments

Comments
 (0)