Skip to content

jasonc/caddy-load-balancing-tutorial

Repository files navigation

Overview:

  • Purpose:
    • Learn how to use Caddy as a web load balancer.
  • Environment:
    • lb01 (load balancer)
    • web01 (web server)
    • web02 (web server)
  • Tools:
    • Caddy for load balancing and web serving.
    • Vagrant for VM creation. (Optional)

Cloning the Tutorial Repository:

  • Command to Clone the Repository:

    git clone https://github.com/jasonc/caddy-load-balancing-tutorial.git
    
  • Change into the Project Directory:

    cd caddy-load-balancing-tutorial
    

Vagrant:

  • Vagrantfiles:

    • Vagrantfile:
      • Automates the installation and configuration of the virtual machines, web servers, and load balancer.
    • Vagrantfile.vms:
      • Creates the virtual machines, but does not install Caddy or perform any configuration.

      • To use, replace Vagrantfile with Vagrantfile.vms:

        cp Vagrantfile.vms Vagrantfile
        
  • Virtual Machine Creation:

    vagrant up
    

Caddy Configuration Files:

  • Caddyfile.random
    • Default random load balancing policy.
  • Caddyfile.ip_hash
    • For IP hash load balancing policy.
  • Caddyfile.rr
    • For round-robin load balancing policy.

Automated Installation Script (install.sh):

  • Adds the Caddy stable repository.
  • Installs Caddy on all nodes.
  • Configures lb01 with the random load balacing policy by using the Caddyfile.random configuration file.
  • Sets up web server hostname in index.html on web01 and web02.

Manual Setup Steps (if not using install.sh):

Load Balancing Configurations:

  • Switching Load Balancer Configurations:
    • Copy the desired Caddyfile to /etc/caddy/Caddyfile on lb01:

      cp Caddyfile.rr /etc/caddy/Caddyfile
      # or
      cp Caddyfile.ip_hash /etc/caddy/Caddyfile
      # or
      cp Caddyfile.random /etc/caddy/Caddyfile
      
    • Reload Caddy:

      sudo systemctl reload caddy
      

Testing Load Balancer:

  • From the command line, use curl to test different load balancing policies:

    curl localhost
    

    Or

    curl 192.168.56.50   # the public facing IP of lb01
    

Additional Resources:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published