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

[proposal] kubectl port-forward listen on custom address #43962

Closed
goblain opened this issue Apr 2, 2017 · 23 comments · Fixed by #46517
Closed

[proposal] kubectl port-forward listen on custom address #43962

goblain opened this issue Apr 2, 2017 · 23 comments · Fixed by #46517
Labels
sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@goblain
Copy link
Contributor

goblain commented Apr 2, 2017

Implementing this proposal that will solve issues raised in #36152 and #29678. In short: allow binding on addresses other then currently supported 127.0.0.1 and ::1

The idea is to implement a new method NewOnAddress in pkg/client/unversioned/portforward/portforward.go that will add an address parameter, and refactor New as a wrapper on the NewOnAddress pointing to "localhost" address.

The NewOnAddress would work as New did previously (that is calling listenOnPortAndAddress) with a difference of setting the new PortForwarder private variable address that can take string representations of IPv4, IPv6, "localhost" or nil. Then listenOnPort will be changed in a way that if IPv4 or IPv6 is provided in PortForwarder.address, the address given wil be the only one used (if it is a valid one). If value "localhost" or nil is passed, it will behave exactly as it does now - listening on 127.0.0.1 and [::1].

pkg/kubectl/cmd/portforward.go will be modified to call NewOnAddress method instead of New with new option address provided by -a or --address flag on kubectl port-forward command and passed via a new string variable Address in updated PortForwardOptions type.

@cblecker
Copy link
Member

cblecker commented Apr 2, 2017

@kubernetes/sig-cli-misc

@fabianofranz
Copy link
Contributor

The CLI part of the proposal looks fine to me, being concise with kubectl proxy. Adding @kubernetes/sig-api-machinery-misc for the client-go bits.

@k8s-github-robot k8s-github-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label May 31, 2017
@0xmichalis
Copy link
Contributor

/sig cli
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jun 15, 2017
@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 15, 2017
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 27, 2017
@CMajeri
Copy link

CMajeri commented Mar 13, 2018

Hi,
I'd be pretty interested in this feature. Is someone currently working on it? @goblain's explanations are spot-on and I could apply them if noone else feels like it.

@goblain
Copy link
Contributor Author

goblain commented Mar 14, 2018

#46517 has implementation (needs a rebase after all that time) but it was put on hold due to feedback from @smarterclayton . No idea if the blocking work was completed so awaiting for confirmation before I invest time in the rebase/refactor.

@CMajeri
Copy link

CMajeri commented Mar 14, 2018

I have no idea how I missed that PR, I'll follow that.

Thanks for the work too, it would really be a nice feature to have!

@chadnickbok
Copy link

@goblain The work has been completed:
#33684

And implemented in the java client at least:
kubernetes-client/java#91

Its frustrating that this very reasonable change was blocked because "other stuff is happening" - other stuff is always happening, and not being able to control the binding address is ridiculous.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 27, 2018
@ghostsquad
Copy link
Contributor

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 27, 2018
@stefanasseg
Copy link

+1

1 similar comment
@gopinatht
Copy link

+1

@goblain
Copy link
Contributor Author

goblain commented Jul 6, 2018

well, I've stopped rebasing the #46517 pull request cause it seems there is no will to merge it in foreseeable future.

@vladimirvivien
Copy link
Member

@goblain are you planning to keep pushing for this to get merged ? I think this is still needed. Just ran into that issue.

@goblain
Copy link
Contributor Author

goblain commented Jul 28, 2018

the decision to go with this is way above me, so I am unable to influence this further. Seems like there simply is no will to merge this into upstream in near future

@pentaphobe
Copy link

+1 here too

Has anyone worked out a reliable workaround in the meantime?

@Baykonur
Copy link

Baykonur commented Aug 3, 2018

+1. Till this is implemented or merged, ssh tunneling can be used on a (yet another) separate terminal (assuming port 8000 is not used on any interface on the host and assuming kubectl port-forward a-pod 8888:8080 executed before):
sudo ssh -N -L 0.0.0.0:8000:localhost:8888 userID@host

and then go to your web-browser and type: http://host:8000

@Jeeppler
Copy link

+1 need this feature as well.

@bgopalakrishnan1986
Copy link

bgopalakrishnan1986 commented Sep 2, 2018

+1 need the feature ASAP

Was able to create a workaround as mentioned by @Baykonur .

Follow the below to work with the actual port itself instead of another temporary one.

kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3002:3000 &

ssh -N -L 0.0.0.0:3000:localhost:3002 userID@host

@tristanveness
Copy link

tristanveness commented Sep 4, 2018

I ran into this issue myself today. Made me very sad sniffle. Especially considering kubectl proxy has all the bells and whistles already :(

      --accept-hosts='^localhost$,^127\.0\.0\.1$,^\[::1\]$': Regular expression for hosts that the proxy should accept.
      --address='127.0.0.1': The IP address on which to serve on.

To workaround this feature not yet being implemented/merged... you can port-forward your already port-forwarded port using socat in another terminal...

socat tcp-listen:9222,fork tcp:127.0.0.1:9223

^ where e.g.

  • 127.0.0.1:9223 is the interface:port kubectl port-forward opened locally
  • and 9222 is the port you want to open on all interfaces (0.0.0.0)

@jwatte
Copy link

jwatte commented Sep 19, 2018

I ran into this, too. kube-proxy does the right thing, why not kube-port-forward?
My use case is "I run a linux VM where I run all the kubectl commands (affecting a cluster hosted in AWS,) and the VM lives inside a Windows host where I run my web browser."
When I want to spin up a new pod in the cluster, and test it out locally without exposing a service to other pods, nor a public address on the cluster, not being able to bind to 0.0.0.0 on my VM is highly inconvenient!

@bw2
Copy link

bw2 commented Sep 21, 2018

Another slight variation on the work-arounds described above using ssh tunnels.

In my case, I'm running minikube with an http web service deployed on NodePort 30003.
I can make it accessible externally on port 80 by running:

sudo ssh -v -i ~/.ssh/id_rsa -N -L 0.0.0.0:80:localhost:30003 ${USER}@$(hostname)

@wjoel
Copy link

wjoel commented Oct 1, 2018

Looks like there is finally some progress on #46517 again, thanks @goblain for all your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
Development

Successfully merging a pull request may close this issue.