HTTP Port Bindings

Hi,

I have a set of stateful set of persistent actors, which are fronted by HTTP routes, also using AKKA clustering. My aim is to run this containerized with Kubernetes to handle load and fail-over. Initially I am trying to test the cluster behavior non-containerized using SBT. When I start the process, what is the best way I can avoid bind conflicts other than specifying the port as CLI argument or environment variable. Currently, the code binds to port 8080 when the first instance starts. Obviously, the second instance gets a bind conflict. What is the best practice in selecting the port in a clustered environment? Can I specify a list of ports, and get the listener to bind to next available in the list?

Kind regards

Hi Alan,

you can use port 0 to have the TCP stack allocate a port number. You can access the actual local address by looking at the ServerBinding value that is returned by the Http().bindAndHandle methods. As I understand, you only need that for testing purposes so it might work?

In an actual containerized environment there shouldn’t be port conflicts.

Johannes

2 Likes

Thank you, Johannes, that worked.