Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Creating a Web Cluster with LXD

Containers allow us to spin up multiple instances quickly and efficiently, making it ideal for spinning up any sort of clustered application or service. In this hands-on lab, we are going to do just that by taking an existing web container and spinning up multiple duplicates, then turning those duplicates into a working web cluster that we can access via the public IP of our server.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Sep 05, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Create a Snapshot of the Provided Container

    Take a snapshot of the container:

    lxc snapshot web01 1.0
    
  2. Challenge

    Create Four Duplicate Containers

    We now want to create four web## containers based on this snapshot. We can do this manually by running lxc copy web/1.0 web## for each container, or by using a Bash script:

    vim /tmp/container-script.sh
    
    containers="web02 web03 web04 web05"
    
    for c in $containers
    do
    	lxc copy web01/1.0 $c
    	lxc start $c
    done
    
    sh /tmp/container-script.sh
    

    Confirm:

    lxc list
    
  3. Challenge

    Create and Configure a Load Balancer Container

    Create a lb01 container, also based on the existing web01/1.0 snapshot:

    lxc copy web01/1.0 lb01
    lxc start lb01
    

    Open and edit the /etc/nginx/conf.d/default.conf file, and set up the load balancer. Remember that host records are set up between containers, so we can use the container names here:

    lxc file edit lb01/etc/nginx/conf.d/default.conf
    
    upstream lb {
            server web01;
            server web02;
            server web03;
            server web04;
            server web05;
    }
    
    server {
            listen 80 default_server;
            listen [::]:80 default_server;
    
            location / {
                    proxy_pass http://lb;
            }
    
    }
    

    Restart nginx:

    lxc exec lb01 -- rc-service nginx restart
    

    Test that we can access the website using curl and the IP of the load balancer:

    lxc list
    curl <lb_ip>
    
  4. Challenge

    Map Ports

    Ensure that when the host's IP is accessed, it forwards to the load balancer container:

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to <lb_ip>:80
    

    Navigate to the public IP of your server in your browser to ensure the load balancer works.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight