omrikiei / ktunnel

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

Expose doesn't work when source and target port are different #31

Closed gotshub closed 3 years ago

gotshub commented 3 years ago

I tried to use the expose command to forward traffic from a kubernetes service to a local port:

ktunnel expose myservice 80:8000

Access from another pod in the same cluster using curl just says:

Failed to connect to myservice port 80: Connection refused

It looks like the service will be created with a source port of 80 and a target port of 8000, but the pod is listening on port 80. When I change the service manually and set source and target port to 80, it works.

omrikiei commented 3 years ago

Hello @gtathub, which port is your local machine listening on?

luislhl commented 3 years ago

I'm having the same issue.

I have a service listening on port 3000 locally. If I run ktunnel expose my-service 8000:3000, then I cannot access it from inside the cluster:

curl: (7) Failed to connect to my-service port 8000: Connection refused

If I then run ktunnel expose my-service 3000:3000, it works, I can access the service in port 3000 from inside the cluster.

omrikiei commented 3 years ago

@luislhl @gtathub I'll try to look into it soon. thank you!

gotshub commented 3 years ago

Hi @omrikiei,

I tried it with a simple python server running at port 8000.

python3 -m http.server 8000

As @luislhl points out, it works with same the source and target port. With different ports, I need to manually change the service to get it working.

omrikiei commented 3 years ago

Hi @gtathub, it seems to be working for me image

Which version of ktunnel are you using?

gotshub commented 3 years ago

Hi @omrikiei,

ah, wait. You were testing the pod and used the port-forward to access port 3000 on the pod, right? I think the ports on the pod are fine. But can you also test the service that was created in Kubernetes by the expose command?

The service should have a different source and target port now (in your case source: 3000 and target: 8000). That means that another pod in the cluster that tries to use this service on port 3000 will be forwarded to your test pod on port 8000 and that leads to the Connection refused message.

By the way, I'm using ktunnel version 1.3.0

omrikiei commented 3 years ago

a fix will be available in ~20 minutes

omrikiei commented 3 years ago

@gtathub @luislhl v1.3.1 with the fix is available through the releases page, and via homebrew. could you kindly confirm the issue is resolved?

gotshub commented 3 years ago

That solved the issue! Thank you!

omrikiei commented 3 years ago

awesome, closing, thank you