Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Intro to go here explaining LXD versus LXC and why you want to use it. For now, key bullets,

  • LXD sits on top of LXC
  • API to orchestrates containers locally and remotely
  • Allows moving and copying between hosts
  • Takes advantage of advanced file systems (in particular ZFS)

You should finish the LXC and LXC with Advanced Networking before starting this article. 

Setup 

A key feature of virtualization technology is taking snapshots. With traditional file systems, this is expensive in terms of storage and speed. Next generation ZFS solves many of theses problems and it is recommended by Ubuntu to install and use with LXD,

Code Block
languagebash
sudo apt install zfsutils-linux # must be using Ubuntu 16.04 or higher.

Next configure LXD,

Code Block
languagebash
sudo lxd init

...

Images

...

Cached Images in Image Store

...

Example "launch" Command ReferenceColumnNote
ubuntu:16.04

ubuntu:6041c5e200b6FINGERPRINTWill specifically reference the specific image in the list.g

...

At this point LXD is all setup and ready to use.

Spinning Up an LXD Container

...Creating and starting a container can be done with one command,

Code Block
languagebash
lxc launch ubuntu:16.04 container01

...

  1. References the ubuntu: Image Server List
    1. Looks for 16.01 images
    2. Matches the current architecture of the machine you are on (in my example 
  2. Checks the cache Image Store for the required image
  3. Download (if not in Image Store) the target image
  4. Setup Container called container01 with default settings
  5. Install the target image into container01
  6. Start container01

Replace launch with init if you would like the container to not start by itself.

We can see the downloaded target image,

...

Code Block
languagebash
lxc list
+-------------+---------+----------------------+------+------------+-----------+
|    NAME     |  STATE  |         IPV4         | IPV6 |    TYPE    | SNAPSHOTS |
+-------------+---------+----------------------+------+------------+-----------+
| container01 | RUNNING | 10.94.217.171 (eth0) |      | PERSISTENT | 0         |
+-------------+---------+----------------------+------+------------+-----------+


# Inspect the container,
lxc info container01


Name: container01
Remote: unix:/var/lib/lxd/unix.socket
Architecture: x86_64
Created: 2016/12/22 03:37 UTC
Status: Running
Type: persistent
Profiles: default
Pid: 19681
Ips:
  eth0:	inet	10.94.217.171	vethDXUYOE
  eth0:	inet6	fe80::216:3eff:fe07:69ea	vethDXUYOE
  lo:	inet	127.0.0.1
  lo:	inet6	::1
Resources:
  Processes: 26
  Disk usage:
    root: 144.32MB
  Memory usage:
    Memory (current): 23.24MB
    Memory (peak): 45.28MB
...

For illustration of flexiblity and preparing for the next section, we will update and setup Apache inside of container01.

Remotely execute update of the container from the host which are run as root,

Code Block
lxc exec container01 apt-get update
lxc exec container01 apt-get dist-upgrade

And now we'll actually create a bash to simulate going in as a console. Notice the prompt change indicating you are root inside of container01,

Code Block
lxc exec container01
root@container01:~#

Now we install Apache and then exit back to our host,

Code Block
languagebash
apt install apache2
exit # Takes you back to your host.


Managing Containers Between Hosts

The most compelling reason to use LXD is that it can be transported easily ability to transport between containers. Setup a second LXD host on the same network. In this example we end up with two hosts,


Advanced Tuning of Containers

Depending on your needs there are advanced configurations options with LXD. Below are key considerations I think about,

  1. Security
  2. Advanced Networking
  3. Capping Resource Utilization
  4. ...

Reference

Gives more details on initializing lxd - https://insights.ubuntu.com/2016/03/16/lxd-2-0-installing-and-configuring-lxd-212/

...