Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support port-mapping when forwarding #121

Closed
adamrodger opened this issue May 20, 2020 · 11 comments
Closed

Support port-mapping when forwarding #121

adamrodger opened this issue May 20, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@adamrodger
Copy link

With a manual kubectl port forward you can map a local port to a different service port, like this:

kubectl port-forward svc/my-service 8080:80

It would be great if kubefwd could support this also but I can't see a current option to do that. I frequently need to forward to pods on port 80 but also have something running locally on port 80 (e.g. running a web UI locally but forwarding to APIs on a cluster).

I don't think we need per-service mapping rules or anything, just a blanket "any service found using port X will be forwarded from local port Y", like:

kubefwd svc -n my-namespace -p 1234:80

Unfortunately I don't know Go otherwise I'd try and implement that myself.

@cjimti
Copy link
Member

cjimti commented May 20, 2020

I am not completely against the idea however it does go against kubefwd central use case, to expose services as they are in the cluster.

kubefwd does set up many forwards to the same port, like web-site1:80, web-site2:80, it does this by using multiple loopback IPs. The problem is that a local service you are running on port 80 is likely bound to all loopback IPs (eg 0.0.0.0). Can you specify an interface for your local service such as 127.0.0.1:80? most applications allow you to do this.

@adamrodger
Copy link
Author

adamrodger commented May 20, 2020 via email

@cjimti
Copy link
Member

cjimti commented May 20, 2020

I am not opposed to your feature request, however, I think it could cause confusion if not implemented clearly, kubfwd is not meant to be a kubectl replacement. kubectl port-forward does exactly what you need.

Many people use kubefwd in an enterprise environment right now. I am curious about how many people have port 80 bound on their workstation.

You might want to try using the Docker container, I know a few people who use it in environments where they don't have superuser access (low ports, etc)...

As for implementation... maybe forwarding maps like -m 8080:80 (meaning any 80 maps to 8080).

kubefwd svc -n proj1 -m 81:80 -m 3307:3306 -m 5601:5600"

BTW there are plenty of enterprises that don't make things like this a PIA for their developers. :)

@adamrodger
Copy link
Author

adamrodger commented May 21, 2020 via email

@cjimti
Copy link
Member

cjimti commented May 21, 2020

@adamrodger you are correct regarding the order. I fixed my comment. Not sure how soon I'll be able to work on this but I see now how it could be helpful in situations like yours.

@cjimti cjimti added the enhancement New feature or request label May 21, 2020
@adamrodger
Copy link
Author

Thanks very much. I'll look forward to it.

@dobesv
Copy link
Contributor

dobesv commented Aug 29, 2020

You can add another port on the service for port 8080 that uses the same target port on the pod. It seems a bit hackish but it's not too bad and it gets the job done. Or even add another entire service for this purpose if need be.

@adamrodger
Copy link
Author

adamrodger commented Mar 6, 2021 via email

@cjimti
Copy link
Member

cjimti commented Mar 6, 2021

I am thinking that "p" might not be a great choice, maybe "m" or something like that. I don't fully understand the use-case since kubefwd uses separate IP addresses for each service. With docker or kubectl it makes sense that you need to specify a local port, especially for low ports like 80 and 443 or forwarding multiple services with the same port.

kubefwd aims to replicate the services as they are in the cluster for development purposes so xdb.accounting:3306 is the same on the cluster as it is local. I don't want to confuse users in thinking they need to (or even should) use this mapping like you would need to use -p for docker or kubectl.

I understand there is a use case where you have some software that listens on all interfaces, such as 0.0.0.0:3306 and is unable to be configured to use 127.0.0.1:3306 but this should be rare. My own team gets tripped up from time to time with local Docker runs, forgetting to specify a local IP docker run -p 8080:8080, and not docker run -p 127.0.0.1:8080:8080

I am ok with the new functionality if we using something other than -p, since port forwarding the service specified port is the implicit feature of kubefwd.

also agree with @adamrodger I think it should be something like kubefwd svc -m 80:8080 -m 443:1443.

@ndj888
Copy link
Contributor

ndj888 commented Mar 7, 2021

I am thinking that "p" might not be a great choice, maybe "m" or something like that. I don't fully understand the use-case since kubefwd uses separate IP addresses for each service. With docker or kubectl it makes sense that you need to specify a local port, especially for low ports like 80 and 443 or forwarding multiple services with the same port.

kubefwd aims to replicate the services as they are in the cluster for development purposes so xdb.accounting:3306 is the same on the cluster as it is local. I don't want to confuse users in thinking they need to (or even should) use this mapping like you would need to use -p for docker or kubectl.

I understand there is a use case where you have some software that listens on all interfaces, such as 0.0.0.0:3306 and is unable to be configured to use 127.0.0.1:3306 but this should be rare. My own team gets tripped up from time to time with local Docker runs, forgetting to specify a local IP docker run -p 8080:8080, and not docker run -p 127.0.0.1:8080:8080

I am ok with the new functionality if we using something other than -p, since port forwarding the service specified port is the implicit feature of kubefwd.

also agree with @adamrodger I think it should be something like kubefwd svc -m 80:8080 -m 443:1443.

That's a good suggestion. To this end I submitted a new pull request.

@cjimti
Copy link
Member

cjimti commented Mar 8, 2021

@ndj888 thanks for work on this. see https://github.com/txn2/kubefwd/releases/tag/1.18.0

@cjimti cjimti closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants