How to add/remove servers from Ha Proxy dynamically using Ha Proxy Data Plane API?

I’ve created simplest pekko-http application in scala.

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.stream.Materializer
import scala.concurrent.ExecutionContextExecutor

object PekkoHttpServer extends App with LogFactoryTrait {
  implicit val system: ActorSystem = ActorSystem("PekkoHttpServer")
  implicit val materializer: Materializer = Materializer(system)
  implicit val executionContext: ExecutionContextExecutor = system.dispatcher

  val route =
    path("hello") {
      get {
        complete("Hello, Pekko HTTP!")
      }
    }

  Http().newServerAt("0.0.0.0", 8090).bind(route)

  logger.info("Server online at http://0.0.0.0:8090/")
}

Then I’ve created its docker image using sbt-native-packager. And I’m running two servers using Ha Proxy.

haproxy/haproxy.cfg:

frontend http
    bind *:8100
    default_backend all
    stats enable
    stats uri /stats
    timeout client 10s

backend all
    mode http
    timeout connect 50s
    timeout server 50s
    balance roundrobin
    option httpchk

    server s1 pekko-ha-proxy-container-1:8090 check inter 5s fall 2 rise 2
    server s2 pekko-ha-proxy-container-2:8090 check inter 5s fall 2 rise 2

docker-compose.yml:

version: "3"

services:
  pekko-ha-proxy-container-1:
    container_name: pekko-ha-proxy-container-1
    image: pekko-ha-proxy:0.0.1
    networks:
      - my-network

  pekko-ha-proxy-container-2:
    container_name: pekko-ha-proxy-container-2
    image: pekko-ha-proxy:0.0.1
    networks:
      - my-network

  haproxy:
    image: haproxy:latest
    ports:
      - "8100:8100"
    volumes:
      - ./haproxy:/usr/local/etc/haproxy
    networks:
      - my-network
    depends_on:
      - pekko-ha-proxy-container-1
      - pekko-ha-proxy-container-2

  networks:
  my-network:
    external: true

When I run docker compose up and hit route http://localhost:8100/hello, it works perfectly fine.

Then I tried to simply run Ha Proxy Data Plane Api. For that:

1. I've downloaded haproxy using apt.

$ sudo apt install haproxy

2. Then downloaded Ha Proxy Data Plane Api.

$ wget https://github.com/haproxytech/dataplaneapi/releases/download/v3.0.3/dataplaneapi_3.0.3_linux_x86_64.tar.gz

3. Extracted it.

tar -zxvf dataplaneapi_3.0.3_linux_x86_64.tar.gz

4. Renamed the file `dataplaneapi.yml.dist` to `dataplaneapi.yml` and move it into my `haproxy` folder.



5. Changed the file paths to the HAProxy program and configuration file:

dataplaneapi.yml:


haproxy:
  config_file: /usr/local/etc/haproxy/haproxy.cfg
  haproxy_bin: /usr/local/sbin/haproxy

haproxy.cfg:

     global
       stats socket /var/run/haproxy.sock mode 660 level admin
       master-worker
       insecure-fork-wanted

     userlist dataplaneapi
       user admin insecure-password adminpwd

     program api
       command /usr/local/bin/dataplaneapi -f /etc/haproxy/dataplaneapi.yml
       no option start-on-reload

docker-compose.yml:

version: "3"

services:
  dataplaneapi:
    image:  haproxytech/haproxy-ubuntu
    container_name: dataplaneapi
    ports:
      - "5555:5555"
    volumes:
      - ${PWD}/haproxy:/usr/local/etc/haproxy:rw
    networks:
      - ifkaar-network

networks:
  ifkaar-network:
    external: true

Now when I run docker compose up and run:

$ curl -X GET --user admin:adminpwd http://localhost:5555/v3/info

It is giving me:

{"api":{"build_date":"2024-08-23T15:38:09.000Z","version":"v3.0.3 1491b08a"},"system":{}}

Means it is also working fine. But I’m unable to combine both things. I want to add/remove my pekko-ha-http-container using Ha Proxy Data Plane Api. Guide me how can I do so? Do I only need dataplaneapi container or haproxy and dataplaneapi both containers?