Search code examples
dockerhaproxyrancher

Map public container port for few private in Rancher


How to map single public port of container for few private ports in Rancher Cattle to make port sink? Maybe i should write custom HAProxy config?

For example:

5555/tcp -> 5555/tcp
5555/tcp -> 5556/tcp
5555/tcp -> 5557/tcp
5555/tcp -> 5558/tcp

Solution

  • What you are asking for is easily possible in Rancher.

    One of the ways of implementing this:

    1. "Add Stack" in Rancher
    2. "Add Service" one (which has the tcp service running on port 5555) to the stack.
    3. "Add Service" two (which has the tcp service running on port 5556) to the stack.
    4. "Add Service" three (which has the tcp service running on port 5557) to the stack.
    5. "Add Service" four (which has the tcp service running on port 5558) to the stack.
    6. "Add Load Balancer" to this stack and configure it.
      • Add port Rule with protocol: tcp, port: 5555 with target to one, port: 5555
      • Add port Rule with protocol: tcp, port: 5555 with target to two, port: 5556
      • Add port Rule with protocol: tcp, port: 5555 with target to three, port: 5557
      • Add port Rule with protocol: tcp, port: 5555 with target to four, port: 5558

    If you want this load balancer to run on all hosts, you can choose that option when creating the load balancer service.

    Also if your service was running on HTTP instead of TCP, you could use that option as well.

    Once you have this working manually you can "View Config" to get the docker-compose.yml and rancher-compose.yml files. You can use them to create your custom catalog item and deploy it in one click!

    Check out the community-catalog for inspiration and the docs for instructions.