While using kubectl port-forward function I was able to succeed in port forwarding a local port to a remote port. However it seems that after a few minutes idling the connection is dropped. Not sure why that is so.
Here is the command used to portforward:
kubectl --namespace somenamespace port-forward somepodname 50051:50051
Error message:
Forwarding from 127.0.0.1:50051 -> 50051
Forwarding from [::1]:50051 -> 50051
E1125 17:18:55.723715 9940 portforward.go:178] lost connection to pod
Was hoping to be able to keep the connection up
Setting kube's
streaming-connection-idle-timeout
to 0 should be a right solution, but if you don't want to change anything, you can use while-do constructionFormat:
while true; do <<YOUR COMMAND HERE>>; done
So just inputing in CLI:
while true; do kubectl --namespace somenamespace port-forward somepodname 50051:50051; done
should keep kubectl reconnecting on connection lostSeems there is a 5 minute timeout that can be overridden with
kubelet
parameters:https://github.com/kubernetes/kubernetes/issues/19231