Skip to content

dalibormesaric/rplb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPLB – Reverse Proxy Load Balancer

Go Build Test Docker Publish

Load balance requests based on configured hostname accross configured backends. It is primarily meant to be used for learning purposes in a home lab environment.

Features

  • ⚙️ Simple configuration
    • In-line
  • ⚡️ Load Balancing
    • Least-Loaded Round Robin
    • Sticky Round Robin
    • Round Robin
    • Random
    • First
  • 💪 Resiliency
    • Retries
  • 📈 Dashboard
    • Monitor
    • Traffic

monitor

traffic

Getting started

Docker

You can run RPLB with these commands:

docker pull ghcr.io/dalibormesaric/rplb:latest

docker run -d --rm -p 8000:8000 -p 8080:8080 -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

Configuration

RPLB_F=myapp.example.com,myapp

  • myapp.example.com is hostname where RPLB is running, so in this case you would access your backend via http://myapp.example.com:8080 and the Dashboard via http://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 assigned
  • http://10.0.0.1:1234, http://10.0.0.2:1234 and http://10.0.0.3:1234 are the URLs of your application

Home Assistant

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.

CLI

Usage of rplb:
  -a string
        Algorithm used for loadbalancing. 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")

Try it out

Example

There is an /example folder in this repository containing already configured RPLB with tree backends. You can try it our by running:

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

traffic gif

Least-Loaded Round Robin

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

Development

Version using Git Tags

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 .

Build Pipeline

Testing

go test ./... -count=1

What is this?

With this project I wanted to have two things:

  1. A simple way to load balance traffic between bare metal kubernetes cluster nodes
  2. A fun Go project to work on

Misc

Tools used

TODO:

  • use RPLB_ prefix in docker environment variables
  • docs
  • algorithm state expiration?
  • favicon on static pages?

Some ideas