Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

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

Path Info

Clock icon Beginner
Clock icon 30m
Clock icon Apr 03, 2020

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/
    containers="web02 web03 web04 web05"
    for c in $containers
    	lxc copy web01/1.0 $c
    	lxc start $c
    sh /tmp/


    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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans