How to run your own lxd demo server

If you are familiar with LXD container then, you may already visited this lxd try it online link. Where you can create LXD container and do some basic operation on a demo server within a given time period (usually 30 minutes). After the time period you will be logout from the container and the container will be deleted automatically. It’s a great place to learn LXD. Today I’ll show you how you can build a similar type of demo server in your own environment. I’m using Ubuntu 16.04 server for the lab.

In Ubuntu 16.04 LXD is installed by default. So its better to remove the deb version of the package. Perform the following for removing the package.

imtiaz@lxd-host:~$ sudo apt remove --purge lxd lxd-client

Then install the LXD snap

imtiaz@lxd-host:~$ sudo snap install lxd

After some downloading activity you will see a message similar like below

lxd 2.8 from 'canonical' installed

Now configure the LXD. For simplicity, I select the default setup except the zfs size (100 GB). You can leave the setup default or if you want, you can customize it.

imtiaz@lxd-host:~$ sudo lxd init
Name of the storage backend to use (dir or zfs) [default=zfs]:
Create a new ZFS pool (yes/no) [default=yes]?
Name of the new ZFS pool [default=lxd]:
Would you like to use an existing block device (yes/no) [default=no]?
Size in GB of the new loop device (1GB minimum) [default=39]: 100
Would you like LXD to be available over the network (yes/no) [default=no]?
Would you like stale cached images to be updated automatically (yes/no) [default=yes]?
Would you like to create a new network bridge (yes/no) [default=yes]?
What should the new bridge be called [default=lxdbr0]?
What IPv4 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
What IPv6 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
LXD has been successfully configured.
imtiaz@lxd-host:~$

At this stage its better to reboot your server and then install the lxd-demo-server.

imtiaz@lxd-host:~$ sudo snap install lxd-demo-server
[sudo] password for imtiaz:
lxd-demo-server git from 'stgraber' installed
imtiaz@lxd-host:~$

Run the following command.

imtiaz@lxd-host:~$ sudo snap connect lxd-demo-server:lxd lxd:lxd

Now if you are using a desktop version, then provide the below link in your browser and hit enter.

http://127.0.0.1:8080

Or, if you are using the server and you want to access the demo server web interface from another machine then you need to do some iptables entry on your server. insert the below rules.

sudo iptables -t nat -A PREROUTING -p tcp -d <YOUR_SERVER_IP> --dport 8080 -j DNAT --to-destination <lxdbro_IP>:8080

change the <YOUR_SERVER_IP> and <lxdbro_IP> according to your setup. ifconfig will help you to find those addresses. go to your browser and enter the following link.

http://<YOUR_SERVER_IP>:8080

For both cases you will see a similar screen on your browser (click the image for better view).

Now if you go to your server command prompt and perform the below command.

imtiaz@lxd-host:~$ lxc list
If this is your first time using LXD, you should also run: sudo lxd init
To start your first container, try: lxc launch ubuntu:16.04

+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
imtiaz@lxd-host:~$

You will see an empty list of container. Now go to your browser and click on “I have read and accept the terms of service above” button. You will see a similar screen like below. It takes some time. Wait until you see the next screen.

And if everything works well then you will see a shell window in your browser like below.

This is the place where you can actually play with your LXD container. You are now inside a LXD container and you can launch your container in this shell. Now if you go back to your host or server shell and perform the lxc list command, then you will see the list is not empty now.

imtiaz@lxd-host:~$ lxc list
+----------------+---------+----------------------+---------------------------------------------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------------+---------+----------------------+---------------------------------------------+------------+-----------+
| tryit-delicate | RUNNING | 10.127.89.190 (eth0) | fd42:cc0e:a817:e40:216:3eff:fe38:24e (eth0) | PERSISTENT | 0 |
+----------------+---------+----------------------+---------------------------------------------+------------+-----------+
imtiaz@lxd-host:~$

As you can see one container name tryit-delicate (it may be different in your case) has been created. This is the container which you are actually seeing in the browser. If you open another session from your browser and perform the following lxc list command you will see that another container will be added to your list. You can open container from the browser until you have reached the maximum number of concurrent sessions. You will see a message like bellow in your browser.

If you want to increase the session limit use the below command to edit your environment.

imtiaz@lxd-host:~$ sudo lxd-demo-server.configure

It will open a file where you can customize the demo server. Like you can increase the number of sessions by editing the “quota_sessions” value. Can add some terms and condition, customize the container resources, etc. Its a nice and good resources for learning LXD container and if you have an environment like this in your own environment then it will be easier to teach people about the technology. Thanks to Canonical Ltd for sharing the tools and have fun with the demo server.

Leave a Reply

Your email address will not be published. Required fields are marked *