omrikiei / ktunnel

A cli that exposes your local resources to kubernetes
GNU General Public License v3.0
913 stars 71 forks source link

Port forwarding error with `ktunnel inject` #102

Closed osintalex closed 1 year ago

osintalex commented 1 year ago

I'm trying to inject to a deployment in line with the Pycharm debugger example but getting these errors:

ktunnel inject deployment <my deployment> -n <my namespace> 4321 is the command and this is the output, redacted in places.

INFO[0000] Injecting tunnel sidecar to <namespace>/<deployment>
INFO[0001] Waiting for deployment to be ready
INFO[0001] ProgressDeadlineInSeconds is currently 600s. It may take this long to detect a deployment failure.
INFO[0040] deployment "<namespace>/<deployment>" successfully rolled out
INFO[0043] port forwarding to https://<ip>/api/v1/namespaces/<my namespace>/pods/<pod name>/portforward
INFO[0043] Waiting for port forward to finish
INFO[0044] Forwarding from 127.0.0.1:28688 -> 28688
Forwarding from [::1]:28688 -> 28688
INFO[2023-03-30 15:01:35.293] starting tcp tunnel from source 4321 to target 4321
E0330 15:01:35.815758   37834 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod <pod hash>, uid : failed to execute portforward in network namespace "/var/run/netns/cni-<uuid>": failed to connect to localhost:28688 inside namespace "<namespace id>", IPv4: dial tcp4 127.0.0.1:28688: connect: connection refused IPv6 dial tcp6 [::1]:28688: connect: cannot assign requested address
ERRO[2023-03-30 15:01:35.815] Error sending init tunnel request: rpc error: code = Unavailable desc = connection closed

I can port forward fine with kubectl and no error logs on the pod. Wondering if it's because it's trying to assign an Ipv6 address rather than ipv4?

omrikiei commented 1 year ago

Could you try changing port from 28688 to a smaller number?

osintalex commented 1 year ago

Yep will try, thanks for the suggestion! How though - I can't see a flag for that on ktunnel inject?

EDIT: just checked out the source code and realised I missed the global port flag, will try this with ktunnel inject deployment <my deployment> -n <my namespace> 4321 --port <port value>

osintalex commented 1 year ago

Same error unfortunately:

E0331 13:31:49.603261   81647 portforward.go:400] an error occurred forwarding 4200 -> 4200: error forwarding port 
4200 to pod <pod hash>, uid : failed to execute portforward in network namespace "/var/run/netns/cni-<network id>": 
failed to connect to localhost:4200 inside namespace "<pod hash>", IPv4: dial tcp4 127.0.0.1:4200: connect: connection 
refused IPv6 dial tcp6 [::1]:4200: connect: cannot assign requested address
osintalex commented 1 year ago

Hmm, I also just tested this on a different deployment in my cluster and it worked fine. I suspect it may therefore be to do with devspace - one one of them I'm running with devspace dev and the other I've just run with devspace deploy.

omrikiei commented 1 year ago

which one was working? dev or deploy?

osintalex commented 1 year ago

Deploy worked fine but I couldn't get dev to work with ktunnel inject.

omrikiei commented 1 year ago

@osintalex it seems that dev mode supports reverse port-forwarding (which is actually pretty cool) why would you need to use ktunnel in that case?

osintalex commented 1 year ago

Oh nice! I didn't know it could do that. So I probably don't need to use ktunnel in that case. Thanks!