Closed minhnhupham closed 5 months ago
Right now, you can redirect several ports to one resource using this command:
kubectl relay ip/10.14.204.99 55432:5432 55433:5433
However, if you try to use this command for many resources, you'll run into a problem:
kubectl relay ip/10.14.204.99 55432:5432 55433:5433 ip/10.14.204.100 1234:1234
-----------------------------------------^
Is the argument a resource or a port detail? This can be confusing.
Because of this, I suggest changing the format of the command interface like this:
kubectl relay \
--port-forward "ip/10.14.204.99 55432:5432 55433:5433" \
--port-forward "ip/10.14.204.100 1234:1234"
This change will still work with the existing argument syntax.
I realize this solution may not be perfect, but it was the first one that came to mind.
Another option would be writing the definitions to a file and make krelay read from there.
Example:
$ kubectl relay --port-forward def.yaml
port-forward:
- resource: "ip/10.14.204.99"
ports:
- "55432:5432"
- "55433:5433"
- resource: "ip/10.14.204.100"
ports:
- "1234:1234"
@knight42, are you open to this modification? I can create a PR for it.
@cenkalti Thanks for your enlightening advice! How about we extend the option B and introduce a configuration file which we can save multiple targets into it. Ref #13.
Let's say we save the user preferences in ~/.config/krelay/config.yml
:
$ cat ~/.config/krelay/config.yml
targets:
- name: a
resource: "ip/10.14.204.99"
ports:
- "55432:5432"
- "55433:5433"
- name: b
resource: "ip/10.14.204.100"
ports:
- "1234"
then we can run krelay like this kubectl relay --targets a,b
or simply kubectl relay -t a,b
. WDYT?
Great idea with the configuration file for flexibility. Using ~/.config/krelay/config.yml and the command examples are straightforward and useful. Good suggestion!
It is a great idea, but would be it possible to make the file location configurable as was initially suggested? Alternatively, is it possible to have a similar functionality without the extra configuration file?
Currently, we share krelay configurations via Git as part of a shell script. Unfortunately, storing the file under ~/.config would make this sharing process impossible.
would be it possible to make the file location configurable as was initially suggested
Yeah the path to the config file should definitely be configurable.
Alternatively, is it possible to have a similar functionality without the extra configuration file
That would be an option too. Actually I kinda lean towards the following syntax proposed above, regarding the introduced complexity of a new config file.
kubectl relay \
--port-forward "ip/10.14.204.99 55432:5432 55433:5433" \
--port-forward "ip/10.14.204.100 1234:1234"
FYI I finally decided to put all the targets in a single file, the path to which can be specified by a new flag -f/--file
. For more details, please refer to #33 .
While #33 is WIP now, the main work has been completed, you could give it a try if possible. Any advice is welcome :)
Works great! Thanks @knight42 🍰
Works great! Thanks @knight42 🍰
Glad to hear that 😄 !
We have a use case where developers are testing their apps locally, the apps connect to multiple endpoints both on the cluster and external to the cluster. Currently we have to launch multiple
krelay
sessions to accomplish this, it seems a bit resource heavy to do this. Ideally we'll like something like this to be supported:kubectl relay ip/10.14.204.99 55432:5432 ip/10.14.204.100 45432:5432
Where we can specify one session and one krelay pod on the cluster to relay to multiple different endpoints. Is this something that can be supported?