I am looking to redirect traffic coming into my Ubuntu instance on port 80 to port 30631 (a NodePort on my kubernetes cluster running on same host).
I added a rule using the below command:
sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 30631
That seems to allow the traffic to reach the NodePort, but it appears when the application is responding to the request, the response is not getting back to the client. I believe this is because the source port needs to be re-written from 30631 to 80.
I tried this, but it didn't work:
sudo iptables -A POSTROUTING -t nat -p tcp --sport 30631 -j SNAT --to-source 192.168.1.70:80
In this case, 192.168.1.70 is the private IP of my Ubuntu host.