- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
Challenge
Create a Snapshot of the Provided Container
Take a snapshot of the container:
lxc snapshot web01 1.0
-
Challenge
Create Four Duplicate Containers
We now want to create four
web##
containers based on this snapshot. We can do this manually by runninglxc 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
-
Challenge
Create and Configure a Load Balancer Container
Create a
lb01
container, also based on the existingweb01/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>
-
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.
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.