Load balance requests based on configured hostname across configured backends. It is primarily meant to be used for learning purposes in a home lab environment.
Read more on Reverse Proxy and Load Balancing.
https://developerschallenges.com/2024/12/09/my-latest-side-project-—-rplb/
- ⚙️ Simple configuration
- In-line
- ⚡️ Load Balancing
- Least-Loaded Round Robin
- Sticky Round Robin
- Round Robin
- Random
- First
- 💪 Resiliency
- Retries
- 📈 Dashboard
- Monitor
- Traffic
- 🧪 Instrumentation
- /metrics endpoint
Usage of rplb:
-a string
Algorithm used for load balancing. Choose from: first, random, roundrobin, sticky or leastloaded. (default "sticky")
-b string
Comma-separated list of BackendPool Name and URL pairs. (example "backend,http://10.0.0.1:1234")
-f string
Comma-separated list of Frontend Hostname and BackendPool Name pairs. (example "frontend.example.com,backend")
You can run RPLB
with these commands:
docker pull ghcr.io/dalibormesaric/rplb:latest
docker run -d --restart=always -p 8000:8000 -p 8080:8080 -e RPLB_A=roundrobin -e RPLB_F=myapp.example.com,myapp -e RPLB_B=myapp,http://10.0.0.1:1234,myapp,http://10.0.0.2:1234,myapp,http://10.0.0.3:1234 --memory="64m" --memory-reservation="64m" --cpus="1" ghcr.io/dalibormesaric/rplb:latest
RPLB_A=roundrobin
roundrobin
is the name of one of the load balancing algorithms
RPLB_F=myapp.example.com,myapp
myapp.example.com
is hostname whereRPLB
is running, so in this case you would access your backend viahttp://myapp.example.com:8080
and the Dashboard viahttp://myapp.example.com:8000
myapp
is name of the Backend Pool that this hostname is connected to
RPLB_B=myapp,http://10.0.0.1:1234,myapp,http://10.0.0.2:1234,myapp,http://10.0.0.3:1234
myapp
is name of the Backend Pool to which the URL is assignedhttp://10.0.0.1:1234
,http://10.0.0.2:1234
andhttp://10.0.0.3:1234
are the URLs of your application
To run custom docker images, use Advanced SSH & Web Terminal from Community Add-ons.
To resolve custom domains on the same IP where Home Assistant is running, use AdGuard Home and its feature DNS rewrites.
There is an /example
folder in this repository containing already configured RPLB
with tree backends. You can try it our by running:
RPLB_A=first docker compose -f example/compose.yaml up rplb --build
for i in {1..10}; do curl -s localhost:8080 | grep \<h1; sleep 1; done;
docker compose -f example/compose.yaml down
RPLB_A=leastloaded docker compose -f example/leastloaded/compose.yaml up rplb --build
seq 1000 | parallel -n0 -j8 "curl -s http://localhost:8080 | grep Response"
docker compose -f example/leastloaded/compose.yaml down
git tag
git tag v0.1
git push origin v0.1
go run -ldflags "-X github.com/dalibormesaric/rplb/internal/config.Version=$(git describe --tags --abbrev=0)" cmd/rplb/main.go
docker build --build-arg="VERSION=$(git describe --tags --abbrev=0)" -t rplb .
go test ./... -count=1
Using https://prometheus.io/docs/guides/go-application/.
Exposing custom metrics.
With this project I wanted to have two things:
- A simple way to load balance traffic between bare metal kubernetes cluster nodes
- A fun Go project to work on
- dashboard page title per page (Monitor - RPLB)
- docs
- algorithm state expiration?
- https://stackoverflow.com/questions/37321760/how-to-set-up-lets-encrypt-for-a-go-server-application
- https://stackoverflow.com/questions/23439126/how-to-mount-a-host-directory-in-a-docker-container
- https://bazel-contrib.github.io/SIG-rules-authors/go-tutorial.html
- https://stackoverflow.com/questions/16512840/get-domain-name-from-ip-address-in-go
- https://stackoverflow.com/questions/70442770/infinite-scrolling-carousel-css-only