You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement port-forwarding to a Service or Deployment #435
Currently port forwarding is linked to a specific pod. However, often what you really want to connect to is a service, so if pods are restarted or removed your port forward continues to function.
The implementation of port forwarding for a service in kubectl simply chooses a pod from that Service's label selector and then port forwards to that pod.
You can implement this using the client by getting the service, getting pods that match the service's selector and then port-forwarding to one of the pods.
If you do implement that feel free to send a PR, we'd gladly take the contribution.
Closing this issue because the question is answered. Please use /reopen if you need any further info.
Thanks for the clarification. We'll keep this as a todo. To set expectations, I'm not sure when someone will have cycles to take it on, especially since it's possible to do this today with the existing client.
If you have time to implement it, we'd gladly take a PR.
@brendanburns Thanks. I'll see whether I have time to work on it. I guess to do it using the client as it is now you would just have to replicate a bunch of code from the port-forward code yourself but change it to automatically select a pod on each connection.
Just to be clear, the kubectl port-forward implementation just chooses a single pod at the start and only forwards to that one pod, it doesn't choose a pod for every connection. I think our implementation should probably be consistent with that, though I don't feel super strongly.
Yes, you are right. Actually looking into this more I see that the kubernetes API for port-forward doesn't support services (yet?), so there's nothing much to be done here until they add that support.
Activity
brendandburns commentedon Apr 21, 2020
The implementation of port forwarding for a service in
kubectlsimply chooses a pod from that Service's label selector and then port forwards to that pod.You can implement this using the client by getting the service, getting pods that match the service's selector and then port-forwarding to one of the pods.
If you do implement that feel free to send a PR, we'd gladly take the contribution.
Closing this issue because the question is answered. Please use
/reopenif you need any further info.dobesv commentedon Apr 21, 2020
Sorry, this wasn't a question, it was a feature request. Are those supposed to be filed somewhere else?
[-]Support port-forward to service instead of pod[/-][+]Implement port-forwarding to a Service or Deployment[/+]brendandburns commentedon Apr 21, 2020
Thanks for the clarification. We'll keep this as a todo. To set expectations, I'm not sure when someone will have cycles to take it on, especially since it's possible to do this today with the existing client.
If you have time to implement it, we'd gladly take a PR.
dobesv commentedon Apr 21, 2020
@brendanburns Thanks. I'll see whether I have time to work on it. I guess to do it using the client as it is now you would just have to replicate a bunch of code from the port-forward code yourself but change it to automatically select a pod on each connection.
brendandburns commentedon Apr 22, 2020
Just to be clear, the
kubectl port-forwardimplementation just chooses a single pod at the start and only forwards to that one pod, it doesn't choose a pod for every connection. I think our implementation should probably be consistent with that, though I don't feel super strongly.dobesv commentedon Apr 22, 2020
Yes, you are right. Actually looking into this more I see that the kubernetes API for port-forward doesn't support services (yet?), so there's nothing much to be done here until they add that support.
dobesv commentedon Apr 22, 2020
See also
kubernetes/kubernetes#15180
kubernetes/kubernetes#59705