Intelligente Lösungen
in neuer Dimension

LXD/LXC mit Ubuntu-16.04 (Xenial)

In diesem Artikel beschreibe ich, wie man LXD und LXC-Container unter Ubuntu-16.04.1 einsetzt. Ich verwende dafür meinen Benutzer “uli”.

  • LXD installieren: sudo apt-get install lxd
  • ZFS installieren: sudo apt-get install zfsutils-linux
  • VolumeGroup ermitteln: sudo vgdisplay|grep Name –> ubuntu1604-64-vg
  • LogicalVolume für ZFS anlegen: sudo lvcreate ubuntu1604-64-vg -n zfslv -L+2G
  • LXD initialisieren: sudo lxd init
    • existing block device? no –> /var/lib/lxd/zfs.img
  • Eigenen Benutzer für LXD bevollmächtigen: sudo usermod -a -G "lxd" uli
  • LXC-Container einrichten: lxc launch ubuntu:16.04 ubuntu-1604
  • Liste der LXC-Container: lxc list
LXD initialisieren
1
2
3
4
5
6
7
8
9
10
11
12
uli@ubuntu1604-64:~$ sudo lxd init
Name of the storage 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]? yes
Path to the existing block device: /dev/ubuntu1604-64-vg/zfslv
Would you like LXD to be available over the network (yes/no) [default=no]? no
Do you want to configure the LXD bridge (yes/no) [default=yes]? yes
Warning: Stopping lxd.service, but it can still be activated by:
  lxd.socket
LXD has been successfully configured.
uli@ubuntu1604-64:~$
LXD bridge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
┌──────────────────────────────┤ Konfiguriere 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?               │  
│                                                                                │  
│                      <Ja>                           Nein                       │  
│                                                                                │  
└────────────────────────────────────────────────────────────────────────────────┘
LXD bridge name
1
2
3
4
5
6
7
8
9
10
┌──────────────┤ Konfiguriere lxd ├──────────────┐                  
│ A valid network interface name (e.g. lxdbr0).  │                  
│                                                │                  
│ Bridge interface name:                         │                  
│                                                │                  
│ lxdbr0________________________________________ │                  
│                                                │                  
│                     <Ok>                       │                  
│                                                │                  
└────────────────────────────────────────────────┘
LXD bridge - IPv4 subnet
1
2
3
4
5
6
7
8
9
┌───────────────────────┤ Konfiguriere lxd ├────────────────────────┐        
│                                                                   │        
│ This is needed to provide IPv4 connectivity for your containers.  │        
│                                                                   │        
│ Do you want to setup an IPv4 subnet?                              │        
│                                                                   │        
│                  <Ja>                       Nein                  │        
│                                                                   │        
└───────────────────────────────────────────────────────────────────┘
LXD bridge - IPv4 random subnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
┌──────────────────────────────┤ Konfiguriere lxd ├──────────────────────────────┐  
│                                                                                │  
│ 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.                                                              │  
│                                                                                │  
│                                     <Ok>                                       │  
│                                                                                │  
└────────────────────────────────────────────────────────────────────────────────┘
LXD bridge - IPv4 address
1
2
3
4
5
6
7
8
9
10
┌──────────┤ Konfiguriere lxd ├──────────┐                      
│ A valid IPv4 address. (e.g. 10.0.8.1)  │                      
│                                        │                      
│ IPv4 address:                          │                      
│                                        │                      
│ 10.16.128.1___________________________ │                      
│                                        │                      
│                 <Ok>                   │                      
│                                        │                      
└────────────────────────────────────────┘
LXD bridge - IPv4 CIDR mask
1
2
3
4
5
6
7
8
9
10
┌─────┤ Konfiguriere lxd ├──────┐                          
│ A valid CIDR mask. (e.g. 24)  │                          
│                               │                          
│ IPv4 CIDR mask:               │                          
│                               │                          
│ 24___________________________ │                          
│                               │                          
│            <Ok>               │                          
│                               │                          
└───────────────────────────────┘
LXD bridge - IPv4 First DHCP address
1
2
3
4
5
6
7
8
9
10
┌─────────────────────┤ Konfiguriere lxd ├──────────────────────┐          
│ The first address to be handed out over DHCP (e.g. 10.0.8.2)  │          
│                                                               │          
│ First DHCP address:                                           │          
│                                                               │          
│ 10.16.128.2__________________________________________________ │          
│                                                               │          
│                            <Ok>                               │          
│                                                               │          
└───────────────────────────────────────────────────────────────┘
LXD bridge - IPv4 Last DHCP address
1
2
3
4
5
6
7
8
9
10
┌──────────────────────┤ Konfiguriere lxd ├──────────────────────┐          
│ The last address to be handed out over DHCP (e.g. 10.0.8.254)  │          
│                                                                │          
│ Last DHCP address:                                             │          
│                                                                │          
│ 10.16.128.254_________________________________________________ │          
│                                                                │          
│                             <Ok>                               │          
│                                                                │          
└────────────────────────────────────────────────────────────────┘
LXD bridge - IPv4 Number of DHCP clients
1
2
3
4
5
6
7
8
9
10
┌────────────────────────┤ Konfiguriere lxd ├─────────────────────────┐       
│ The maximum number of DHCP leases that can be obtained. (e.g. 250)  │       
│                                                                     │       
│ Max number of DHCP clients:                                         │       
│                                                                     │       
│ 252________________________________________________________________ │       
│                                                                     │       
│                               <Ok>                                  │       
│                                                                     │       
└─────────────────────────────────────────────────────────────────────┘
LXD bridge - IPv4 NAT
1
2
3
4
5
6
7
8
9
┌────────────────────┤ Konfiguriere lxd ├────────────────────┐            
│                                                            │            
│ This is needed unless you are using a routed IPv4 subnet.  │            
│                                                            │            
│ Do you want to NAT the IPv4 traffic?                       │            
│                                                            │            
│               <Ja>                    Nein                 │            
│                                                            │            
└────────────────────────────────────────────────────────────┘
LXD bridge - IPv6 subnet
1
2
3
4
5
6
7
8
9
┌───────────────────────┤ Konfiguriere lxd ├────────────────────────┐        
│                                                                   │        
│ This is needed to provide IPv6 connectivity for your containers.  │        
│                                                                   │        
│ Do you want to setup an IPv6 subnet?                              │        
│                                                                   │        
│                   Ja                       <Nein>                 │        
│                                                                   │        
└───────────────────────────────────────────────────────────────────┘
LXC Container einrichten
1
2
3
4
5
6
7
8
uli@ubuntu1604-64:~$ lxc launch ubuntu:16.04 ubuntu-1604
Generating a client certificate. This may take a minute...
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

ubuntu-1604 wird erstellt
Retrieving image: 100%
ubuntu-1604 wird gestartet
LXC-Liste anzeigen
1
2
3
4
5
6
uli@ubuntu1604-64:~$ lxc list
+-------------+---------+---------------------+------+------------+-----------------+
|    NAME     | STATUS  |        IPV4         | IPV6 |    TYP     | SCHNAPPSCHÜSSE |
+-------------+---------+---------------------+------+------------+-----------------+
| ubuntu-1604 | RUNNING | 10.16.128.86 (eth0) |      | PERSISTENT | 0               |
+-------------+---------+---------------------+------+------------+-----------------+