Fix kube port-forward to exit on pod removal#57051
Conversation
|
Looks good so far, but we'll need to update the websocket version as well, right? |
tigrato
left a comment
There was a problem hiding this comment.
Can you also include an integration test for this functionality?
We run a kind cluster in our CI so this should be trivial to model with a real Kubernetes cluster and native SPDY + SPDY over websocket protocol
@creack Here's a summary of the additions to
|
creack
left a comment
There was a problem hiding this comment.
Maybe I am missing something, but I still can reproduce the issue on 35ce01b.
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080
Even after deleting the pod, it keeps handling the connections.
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80Port forward:
tsh kube login kind1
kubectl apply -f deploy.yaml
kubectl port-forward deployments/nginx 8080:80Check loop:
while true; do curl localhost:8080; sleep 1; doneScale down:
kubectl scale deployment nginx --replicas=0After scale down, curl returns:
curl: (52) Empty reply from server
instead of
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server
and the port-forward doesn't exits.
It was user error. Helm using a different version as the built one. Sorry about this. Tested properly and confirmed it works as expected. |
fspmarshall
left a comment
There was a problem hiding this comment.
LGTM once the pending points are resolved.
kubectl port-forward now exits cleanly when backend pods are removed2e54b37 to
271a4f0
Compare
`kubectl port-forward` now exits when a pod disconnects. This addresses `kubectl` user expectations that the Teleport Kubernetes proxy behave transparently, and identical to direct-to-Kubernetes. - Changed error stream copying to uni-directional (target -> source) in SPDY and WebSocket `forwardStreamPair()` functions - Added `WaitGroup` to SPDY `run()` enabling all port-forward streams to fully complete before returning - Added an integration test for Kubernetes port-forwarding with pod disconnection - Updated existing port-forward integration tests to allow and expect `ErrLostConnectionToPod` Fixes #54814
271a4f0 to
2cee6be
Compare
Fixes #54814
kubectl port-forwardnow exits when a pod disconnects.This addresses
kubectluser expectations that the Teleport Kubernetes proxy behave transparently, and identical to direct-to-Kubernetes. Previouslykubectlover Teleport port-forwarding would remain open indefinitely even though no pods were available. That behavior was different from thekubectldirect-to-Kubernetes experience.In this PR:
forwardStreamPair()functionsWaitGroupto SPDYrun()enabling all port-forward streams to fully complete before returningErrLostConnectionToPodManual Bug Reproduction
The bug was manually reproduced using
kubectldirect-to-Kubernetes, andkubectlover Teleport.Bug Behavior (Teleport)
Observing the bug with
kubectland Teleport.Here we see the
kubectl port-forwardprocess running after all pods are removed.Expected Behavior (Direct k8s)
Observing
kubectlbehavior when directly connected to Kubernetes (no Teleport).Here we see the
kubectl port-forwardprocess exits after all pods are removed.Fix Behavior (Teleport)
Observing the fix with
kubectland Teleport.Here we see the
kubectl port-forwardprocess exits after all pods are removed.Changelog: Kubernetes Access:
kubectl port-forwardnow exits cleanly when backend pods are removed