...
A key feature of virtualization technology is taking snapshots and cloning. With traditional file systems, this is expensive in terms of storage and speed. Next generation The next generation volume manager and file system ZFS solves many of theses problems and it is recommended by Ubuntu to install and use with LXD,
Code Block | ||
---|---|---|
| ||
sudo apt-get install bridge-utils zfsutils-linux # must be using Ubuntu 16.04 or higher. |
The other key feature to use with LXD is network bridging. By it's nature, the containers created by LXD exist in their own network. The network bridge utils allow you to expose your container to the rest of the network,
Code Block | ||
---|---|---|
| ||
sudo apt-get install lxd |
...
bridge-utils |
Finally install LXD,
Code Block | ||
---|---|---|
| ||
sudo lxd init |
Pretty much first set are defaults. Will add notes about ZFS. Should explain loop device here too. Note Roderick using Azure Ubuntu 16.10 has simpler following screens,
apt-get install lxd |
Initial Configuration
Before using LXD you need to to do an initial configuration.
The configuration is evolving and you will notice differences between versions of Ubuntu. Because the material is rather tough, we'll archive the older Ubuntu lxd init and keep the most current release here,
LXD Init for LTS
Code Block | ||
---|---|---|
| ||
Name# ofshow theversion storageof backend to use (dir or zfs) [default=zfs]: zfs Create a new ZFS pool (yes/no) [default=yes]? yes Name of the new ZFS pool [default=lxd]: lxd Would you like to use an existing block device (yes/no) [default=no]? no Size in GB of the new loop device (1GB minimum) [default=15]: 15 Would you like LXD to be available over the network (yes/no) [default=no]? no Would you like stale cached images to be updated automatically (yes/no) [default=yes]? yes Would you like to create a new network bridgeUbuntu, lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial # initialize LXD sudo lxd init |
For the most part you will be able to hit Enter and accept defaults. Some options you may go back and change but others will require lots of work so take your time.
I'll go over some of the more confusing options,
Code Block | ||
---|---|---|
| ||
Name of the storage backend to use (dir or zfs) [default=zfs]: Create a new ZFS pool (yes/no) [default=yes]? yes What should the new bridge be called [default=lxdbr0]? lxdbr0 What IPv4 subnet should be used (CIDR notation, "auto" or "none") [default=auto]? auto What IPv6 subnet should be used (CIDR notation, "auto" or "none") [default=auto]? auto LXD has been successfully configured. |
Tin using Ubuntu 16.04.1
Code Block | ||
---|---|---|
| ||
Name of the new ZFS pool [default=lxd]: lxd Would you like to use an existing block device (yes/no) [default=no]? no Size in GB of the new loop device (1GB minimum) [default=1518]: 15 |
LXD allows management over the network. This is useful in an environment with multiple host LXDs and you want the ability to centrally manage. In this article, I am choosing yes because we'll later use Virtual Machine Manager to show GUI management,
Code Block | ||
---|---|---|
| ||
Would you like LXD to be available over the network (yes/no) [default=no]? noyes WouldAddress youto likebind staleLXD cached images to be(not updated automatically (yes/noincluding port) [default=yesall]?: yes WouldPort you like to createbind aLXD new network bridge (yes/no) to [default=yes8443]?: yes WhatTrust shouldpassword thefor new bridgeclients: be called [default=lxdbr0]? lxdbr0 What IPv4 subnet should be used (CIDR notation, "auto" or "none") [default=auto]? auto What IPv6 subnet should be used (CIDR notation, "auto" or "none") [default=auto]? auto LXD has been successfully configured. |
...
Again: |
LXD init will configure a bridge. In order to say yes to this you must have the bridge utils installed. In this article we covered that so say yes
Code Block | ||
---|---|---|
| ||
WouldDo you likewant to createconfigure athe newLXD network bridge (yes/no) [default=yes]? <yes> What should the new bridge be called [default=lxdbr0]? <Ok> Do you want to setup an IPv4 subnet? <yes> This subnet was selected for your convenience and next questions have been pre-answered accodingly. Please make sure this subnet isn't already in use somewhere on your network, if it is, change it to one which isn't. If you later notice network connectivity issues, re-configure lxd and pick a different subnet. <Ok> # resulting IPv4 address will vary in this example using VMWare fusion it is 10.232.27.1 <Ok> ... all sorts of things... need to redo this. |
If you need to reconfigure the bridge you can by using this command.
Code Block | ||
---|---|---|
| ||
sudo dpkg-reconfigure -p medium lxd |
...
You will be prompted with a "text ui" interface. Use your arrow keys to pick the buttons.
Introduction,
Panel |
---|
Conifiguring lxd Containers need a bridge to connect them together and to the host for outside network connectivity. Choosing this option will let you configure the default LXD bridge to your liking. If you would rather not have LXD do this for you, then you will be asked whether you want to use an existing bridge or just do everything manually. Would you like to setup a network bridge for LXD containers now? Yes |
The default bridge name is lxdbr0. It's just a name but suggest you leave as default. To get to the button, use the down arrow key,
Panel |
---|
Conifiguring lxd A valid network interface name (e.g. lxdbr0). Bridge interface name: lxdbr0 Ok |
Go with IPv4 unless you have some special need to use IPv6,
Panel |
---|
This is needed to provide IPv4 connectivity for your containers. Do you want to setup an IPv4 subnet? Yes |
You will be assigned a random subnet. For the purposes of this article, think of a subnet as a way of naming your postal code. It's the difference between Canada and US postal code. When given time I'll provide more description and write or link to a good article on subnets,
Panel |
---|
A random subnet was selected for you. This subnet was selected for your convenience and the next questions have been pre-answered accordingly. Please make sure this subnet isn't already in use somewhere on your network, if it is, change it to one which isn't. If you later notice network connectivity issues, re-configure lxd and pick a different subnet. Yes |
IPv4 address. This prompt is not very clear. Going to go back and check shortly. It is either reserving this IP address or asking you for a sample to determine the subnet.
Panel |
---|
A valid IPv4 address. (e.g. 10.0.8.1): 10.139.135.1 Ok |
A valid CIDR mask. (e.g. 24),
Panel |
---|
IPv4 CIDR mask:: 24 Ok |
Initial IP Address Range does not matter unless you want to use a lot of static IP addresses. I need to think about this a bit more... the idealism behind cloud is not require static, but reality (at least for now), I still find static useful and in some application designs (stateful apps, older PKI's... ect...) absolutely necessary.
Panel |
---|
The first address to be handed out over DHCP (e.g. 10.0.8.2) First DHCP address: 10.139.135.2 Ok |
Pick default for the last address,
Panel |
---|
The last address to be handed out over DHCP (e.g. 10.0.8.254) Last DHCP address: 10.139.135.254 Ok |
The DHCP leas number should be default unless you went and changed the range. If so you should adjust to match. Yeah I know the numbers do not add up (254 - 2 = 252) but I believe there is some fancy math for that... look up and link to my LXC articles.
Panel |
---|
The maximum number of DHCP leases that can be obtained. (e.g. 250) Max number of DHCP clients: 250 Ok |
For almost all networks this will be Yes. Tin google or to talk to Dickson or Andrew though at some point to put explanations here.
Panel |
---|
This is needed unless you are using a routed IPv4 subnet. Do you want to NAT the IPv4 traffic? Yes |
Unless you really need IPv6 say no,
Panel |
---|
This is needed to provide IPv6 connectivity for your containers. Do you want to setup an IPv6 subnet? No |
After this you will be taken out of the Text UI. The warning message is due to network bridge setup,
Code Block | ||
---|---|---|
| ||
Warning: Stopping lxd.service, but it can still be activated by:
lxd.socket
LXD has been successfully configured. |
I hate doing this in Linux, but let's reboot to make sure the lxd service is ok,
Code Block | ||
---|---|---|
| ||
sudo reboot |
Add Users to the lxd Group
By default, users cannot yet use LXD until you add them to the reserved group. In this example, I'm adding my account,
Code Block | ||
---|---|---|
| ||
sudo usermod -a -G lxd usernametin.pham |
Reminder that if you use your own account, you need to log out then log back in.
Verify LXD is Working
Basic test to verify lxd is working and it will also generate your random client certificate (used by LXD to secure calls) on your account,
Code Block | ||
---|---|---|
| ||
lxc image list
+-------+-------------+--------+-------------+------+------+-------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE |
+-------+-------------+--------+-------------+------+------+-------------+ |
At this point we have no LXD images.
Basic LXD Commands
To view your bridge information.
Code Block | ||
---|---|---|
| ||
lxc profile edit default |
Notice the following,
Code Block | ||
---|---|---|
| ||
name: default config: {} description: Default LXD profile devices: eth0: nictype: bridged parent: lxdbr0 type: nic name: default |
What we see here is that the containers will be handed IPs from the LXD bridge and exist within the LXD network.
Warning |
---|
Tin is refining the 2nd pass of this article ... I am currently at this point. |
Images
...
Cached Images in Image Store
...
Image Server LIst | Purpose | Comment |
---|---|---|
ubuntu: | Ubuntu stable images. | We'll be working with this one. |
ubuntu-daily: | ||
images: | All Linux distributionsdistriibutions. | For example you can load a RedHat Linux alternative distrobution. |
...
Code Block | ||
---|---|---|
| ||
lxc image list ubuntu: | less
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE |
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+
| p (5 more) | 6041c5e200b6 | yes | ubuntu 12.04 LTS amd64 (release) (20161205) | x86_64 | 156.47MB | Dec 5, 2016 at 12:00am (UTC) |
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+
| p/armhf (2 more) | c19b1fff3336 | yes | ubuntu 12.04 LTS armhf (release) (20161205) | armv7l | 135.19MB | Dec 5, 2016 at 12:00am (UTC) |
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+
| p/i386 (2 more) | ce5c6821eebb | yes | ubuntu 12.04 LTS i386 (release) (20161205) | i686 | 139.28MB | Dec 5, 2016 at 12:00am (UTC) |
+--------------------+--------------+--------+-------------------------------------------------+---------+----------+-------------------------------+
...
# Reduce the list to your machine architecture, in my case and most it will be amd64
lxc image list ubuntu: amd64 |
The output table from list is not very clear. I don't understand what to reference to use What you reference when using the "launch" command . Will put explanation here once figured out. Here is what I can tellis the main part of the ALIAS name ignoring anything in brackets. For example to install and launch other distrobusions based off of the images: list which has all Linux distributions,
Example "launch" Command Reference | Column | Note |
---|---|---|
ubuntu:16.04 | This will download from the Ubuntu image server grabbing the latest 16.04 matching your machines architecture, win in my case amd64. | |
ubuntu:6041c5e200b6 | FINGERPRINT | Will specifically reference the specific image in the list. |
images:centos/7 | Go against the "images" image server, download the latest cantos version 7 matching your machines architecture. | |
images:centos/6/amd64 | In this example, specifies Specifies the latest version 6 and specifies the architecture to use. |
At this point LXD is all setup and ready to use.
...
There are two key methods. Clone semi-live using snapshots and shutting down first.
Note |
---|
Investigate if cloning between different lxd versions is supported and to what extent. |
Shutdown Approach
Log into myhost02
...
Code Block | ||
---|---|---|
| ||
lxc file push sourcefile container/path/to/directory/ lxc file pull container/path/to/file directory |
Reconfigure
If you need to reconfigure the bridge you can by using this command.
Code Block | ||
---|---|---|
| ||
sudo dpkg-reconfigure -p medium lxd |
Reference
Initializing LXD - https://insights.ubuntu.com/2016/03/16/lxd-2-0-installing-and-configuring-lxd-212/
...
Live Container Migrations - https://bobcares.com/blog/lxc-live-migration-to-minimize-business-downtime/
Mounting a local folder - https://tribaal.io/nicer-mounting-home-in-lxd.html