

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Offline
incomplete
2: Break the Network
incomplete
3: Load Balancers
incomplete
4: Application Servers
incomplete
5: Custom Network
incomplete
6: Configuring the Load Balancer
incomplete
This lesson's interactive features are locked, please to keep using them
We've confirmed that we have 2 application servers (Caddy) working properly on a custom bridge network. Let's create a load balancer that balances network requests between the two! We'll use a round-robin balancing strategy, so each request should route back and forth between the servers.
Caddy works great as a file server, which is what our little HTML servers are, but it also works great as a load balancer! To use Caddy as a load balancer we'll need to create a custom Caddyfile to tell Caddy how we want it to balance the traffic. It's just a config file for Caddy.
localhost:80
reverse_proxy caddy1:80 caddy2:80 {
lb_policy round_robin
}
This tells Caddy to run on localhost:80, and to round robin any incoming traffic to caddy1:80 and caddy2:80. Remember, this only works because we're going to run the loadbalancer on the same network, so caddy1 and caddy2 will automatically resolve to our application server's containers.
docker run -d --network caddytest -p 8880:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile caddy
If it's not swapping properly, try using curl instead. Your browser might be caching the HTML.
curl http://localhost:8880/
Run and submit the CLI tests.