You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -107,9 +107,15 @@ These workarounds add complexity, security concerns, and maintenance overhead. A
107
107
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:
108
108
109
109
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
# 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
129
136
```
130
137
131
-
#### Story 2: Testing Webhooks in Development
138
+
#### Story 2: Testing Sidecar Proxy with Local Policy Service
132
139
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.
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:**
233
259
234
260
```mermaid
235
261
sequenceDiagram
@@ -260,7 +286,7 @@ sequenceDiagram
260
286
kubectl->>User: Deliver response
261
287
```
262
288
263
-
**5. Implementation Components:**
289
+
**6. Implementation Components:**
264
290
265
291
-**Port Listener**: Create a TCP listener in the pod's network namespace
266
292
- Native Go implementation using a Go network namespace library (such as [vishvananda/netns](https://github.com/vishvananda/netns)).
0 commit comments