Manipulare containere in LXD

Postat la Thu 26 April 2018 in tutoriale, lxd, lxc

Containerele LXD folosesc pentru start imagini preconfigurate din repository externe sau locale. Surse principale de imagini de boot sunt linuxcontainers.org si Ubuntu.

Aceste surse sunt numite remote in LXD:

lxc remote list
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
|      NAME       |                   URL                    |   PROTOCOL    | AUTH TYPE | PUBLIC | STATIC |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| images          | https://images.linuxcontainers.org       | simplestreams |           | YES    | NO     |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| local (default) | unix://                                  | lxd           | tls       | NO     | YES    |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| ubuntu          | https://cloud-images.ubuntu.com/releases | simplestreams |           | YES    | YES    |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| ubuntu-daily    | https://cloud-images.ubuntu.com/daily    | simplestreams |           | YES    | YES    |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+

Imaginile diponibile in aceste surse pot fi listate sau cautate facil:

lxc image list images:

lxc image list images:debian

Pornirea unui container se face usor specificand sursa imaginii pe care o dorim sa o folosim si se va aplica profilul default existent

lxc launch images:debian/10 d1

lxc launch images:centos/7/amd c7

In cazul in care dorim sa folosim un profil definit anterior:

lxc launch images:debian/10 d1 -p dual

De asemenea LXD suporta crearea ca instantele de la principalii provideri de cloud (AWS, Azure, Google Cloud) sau personalizate:

  • <instance type>
  • <cloud>:<instance type>
  • c<CPU>-m<RAM in GB>
lxc launch images:ubuntu/18.04 u1 -t t1.micro

lxc launch images:ubuntu/18.04 u1 -t c1-m4

Lista instantelor recunoscute de LXD o puteti consulta pe github.

Informatii desre containerele create il putem afla rapid:

lxc list
+-------------+---------+-----------------------+------+------------+-----------+
|    NAME     |  STATE  |         IPV4          | IPV6 |    TYPE    | SNAPSHOTS |
+-------------+---------+-----------------------+------+------------+-----------+
| bionic      | RUNNING | 192.168.25.112 (eth0) |      | PERSISTENT | 0         |
+-------------+---------+-----------------------+------+------------+-----------+
| salt-master | RUNNING | 192.168.25.115 (eth0) |      | PERSISTENT | 1         |
|             |         | 10.213.199.121 (eth1) |      |            |           |
+-------------+---------+-----------------------+------+------------+-----------+

unde aflam statusul in care se afla, adresele primite.

Informatii mai detaliate putem obtine referitor la containerele create:

lxc config show bionic
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Ubuntu bionic amd64 (20180426_03:49)
  image.os: Ubuntu
  image.release: bionic
  image.serial: "20180426_03:49"
  limits.cpu: "1"
  limits.memory: 1024MB
  volatile.base_image: 7701a7d0197ee22454ef2db8b994617ce3c65cdb2d30d961801a399173e261a9
  volatile.eth0.hwaddr: 00:16:3e:a0:a5:15
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":100000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":100000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

Initial aceste containere nu au instalate ssh pentru conectare dar pot fi accesate si pot avea useri default ca ubuntu sau centos.

lxc exec bionic bash
root@bionic:~#

In acest moment accesul este similar cu orice server instalat pe masina fizica sau Virtualbox cu diferenta ca numarul de procese pe care il vedem ca containerul ruleaza este mult mai mic:

root@bionic:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.5  77120  5636 ?        Ss   15:56   0:00 /sbin/init
root        38  0.0  0.6  78500  7304 ?        Ss   15:56   0:00 /lib/systemd/systemd-journald
root        55  0.0  0.1  42104  2076 ?        Ss   15:56   0:00 /lib/systemd/systemd-udevd
systemd+    68  0.0  0.3  80012  3924 ?        Ss   15:56   0:00 /lib/systemd/systemd-networkd
syslog      77  0.0  0.2 193400  2724 ?        Ssl  15:56   0:00 /usr/sbin/rsyslogd -n
message+    78  0.0  0.2  49928  2524 ?        Ss   15:56   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation -
root        81  0.0  0.3  61996  3748 ?        Ss   15:56   0:00 /lib/systemd/systemd-logind
root        82  0.0  1.2 170364 13476 ?        Ssl  15:56   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher
root        83  0.0  0.1  31292  1796 ?        Ss   15:56   0:00 /usr/sbin/cron -f
systemd+    84  0.0  0.3  70608  4004 ?        Ss   15:56   0:00 /lib/systemd/systemd-resolved
root        86  0.0  0.1  15956  1408 console  Ss+  15:56   0:00 /sbin/agetty -o -p -- \u --noclear --keep-baud console 115200,38400,9600 linux
root       111  0.0  0.2  23192  2688 ?        Ss   16:22   0:00 bash
root       124  0.0  0.2  39084  2144 ?        R+   16:23   0:00 ps aux

Containerele pot fi oprite, repornite, sterse foarte rapid cu timpi de executie mult mai mici decat in KVM, VirtualBox:

lxc stop bionic

lxc restart bionic

lxc delete bionic

time lxc restart bionic
lxc restart bionic  0.01s user 0.02s system 1% cpu 2.044 total
time lxc stop bionic
lxc stop bionic  0.01s user 0.01s system 1% cpu 1.199 total
time lxc start bionic
lxc start bionic  0.01s user 0.01s system 2% cpu 0.869 total

Articolul face parte din seria Virtualizare cu LXD