Skip to content

Implement port-forwarding to a Service or Deployment #435

Closed

Description

@dobesv

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.

Activity

  1. brendandburns commented on Apr 21, 2020

    @brendandburns
    Contributor

    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.

  2. dobesv commented on Apr 21, 2020

    @dobesv
    Author

    Sorry, this wasn't a question, it was a feature request. Are those supposed to be filed somewhere else?

  3. changed the title [-]Support port-forward to service instead of pod[/-] [+]Implement port-forwarding to a Service or Deployment[/+] on Apr 21, 2020
  4. brendandburns commented on Apr 21, 2020

    @brendandburns
    Contributor

    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.

  5. dobesv commented on Apr 21, 2020

    @dobesv
    Author

    @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.

  6. brendandburns commented on Apr 22, 2020

    @brendandburns
    Contributor

    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.

  7. dobesv commented on Apr 22, 2020

    @dobesv
    Author

    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.

  8. dobesv commented on Apr 22, 2020

    @dobesv
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions