https://rancher.com/ logo
Title
p

powerful-ocean-51915

05/02/2023, 6:50 PM
Hi, I'm trying to use the port-forwarding option on the Rancher Desktop GUI to forward messages from my local machine, i.e. localhost, to my rancher kubernetes cluster. When I run the "kubectl port forward <service> <localport>:<clusterport>" on the command line from my local machine it communicates with the cluster fine but the port forwarding on Rancher Desktop, given the same connection details doesn't work. Can anyone shed any light on this?
r

rapid-eye-50641

05/02/2023, 9:47 PM
I am not sure if i understood your issue correctly. The purpose of
Port Forwarding
is to expose the services running in your cluster to your local machine. Can you share some information about the exact steps you are following to help me understand your issue please?
p

powerful-ocean-51915

05/03/2023, 11:11 AM
Hi, thanks for responding. So I'm connecting to a kakfa service, if I run kubectl port-forward svc/kafka 30092:9092, this works great. So this is port forwarding from my local machine on port 30092 to the cluster's internal kafka service listening on 9092. If I go to the Rancher GUI, and add what I think is the equivalent, it doesn't work.....
r

rapid-eye-50641

05/03/2023, 5:01 PM
@powerful-ocean-51915, thanks for providing additional information. Can you please try below simple example and see it works. Just to rule it's not something fundamental related to the Port Forwarding feature on your machine.
kubectl create deployment nginx-test --image=nginx --port=80
kubectl create service clusterip nginx-test --tcp=5000:80
.. and then forward the service to the host machine port
30092
from the GUI. You should see the NGINX welcome page when you open
<http://localhost:30092/>
in your browser.
Also, which operating system are you on?
p

powerful-ocean-51915

05/04/2023, 12:04 PM
Hi
Your example works. I'm connecting from WSL2 running on Windows 11 and I think that's the issue. So I've tried MySQL (which I have running in the cluster), I've enabled rancher port-forwarding from localhost:30306 to 3306 and I can connect from my Spring Boot App and from MySQL workbench using localhost:30306 but not from MySQL client running on WSL2 and I can't connect to Kafka from WSL2 via the port forwarding either but I can from my spring boot app. I think it's pretty clear that Rancher port forwarding is working. Thank you for responding. I don't understand why it's not working from WSL2 but I can look into that. Can you answer one further question on Port Forwarding. Can you persist port-forwarding settings between Rancher reboots?
r

rapid-eye-50641

05/04/2023, 2:54 PM
Sure, Please keep us posted what you find out with kafka. And, port-forwarding is not persisted between reboots at present. There's a GitHub issue for this. Please give a thumbs up on the issue, which helps us gauge user's interest for this enhancement and lets us prioritize. Thank you. https://github.com/rancher-sandbox/rancher-desktop/issues/3563
p

powerful-ocean-51915

05/05/2023, 2:49 PM
I will keep you posted and I have left a comment supporting the port forward persistence on github. Thanks so much for your help :-)
A further question on port forwarding, if we can't, in the short-term, have port-forwarding persistence is there anyway we can run a script to re-set the port forwarding?