SlideShare a Scribd company logo
1 of 66
Download to read offline
Ubuntuで始めるコンテナ技術入門
Presentation by
Takenori Matsumoto
takenori.matsumoto@canonical.com
Hands-on session by
Yoshi Kadokawa
yoshi.kadokawa@canonical.com
Agenda
● 1. コンテナ関連技術の歴史の振り返り
● 2. LXCの歴史
● 3. LXCの特徴と利点
● 4. LXCの仕組み
● ハンズオンセッション
● [オマケ①] JujuでLXC
● [オマケ②] LXD (lex-dee)紹介
1. コンテナ技術の歴史
コンテナ技術の歴史
出展: http://en.wikipedia.org/wiki/Operating-system-level_virtualization
コンテナ技術の歴史
chroot → FreeBSD jail → LXC
コンテナ技術の歴史
chroot
大雑把に言って、
● ディレクトリーツリーの分離
● プロセスリストが共有
ユースケース/モチベーションは、
● 開発者向けのテスト/ビルド用
コンテナ技術の歴史
FreeBSD Jail
大雑把に言って、
● プロセスリスト、ネットワークスタックも分離(隔
離)
● # ごめんなさい。不勉強です。
ユースケース/モチベーションは、
● root権限を一般ユーザにも委譲
● ホスティングサービス
コンテナ技術の歴史
LXC
大雑把に言って、
● 一通りのリソース管理テーブルを隔離
● システムリソース(cpu, ディスク, メモリ等)の制御
ユースケース/モチベーションは、
● 軽量仮想環境
2. LXCの歴史
LXCの中核
● Linuxカーネルの標準機能
○ Namespace: コンテナごとのリソース管理
テーブル
○ Cgroup: システムリソース(cpu, blkio,
net_cls等)の制御
徐々にLinuxカーネルに実装されてきて、カーネル
3.12くらいで、一通りの機能が実装。
LXCの歴史
LXCの歴史
● Namespaceの歴史
Namespace Linux kernel 隔離対象
Mount
namespaces
2.4.19 ファイルシステムマウント
UTS namespaces 2.6.19 ノード名、ドメイン名
IPC namespaces 2.6.19 IPC (interprocess communication)
PID namespaces 2.6.24 プロセスID
Network
namespaces
2.6.29 ネットワークデバイス, IPアドレス, ルー
ティングテーブル, /proc/net, ポート番
号, など
User namespaces 3.8 UID, GID
参考: http://lwn.net/Articles/531114/
LXCの歴史
● Ubuntuとの関わり
Ubuntu
Version
LXC version Kernel version
12.04LTS 0.7.5 (universe) v3.2.14
12.10 0.8.0 (universe) v3.5.5
13.04 0.9.0 (universe) v3.8.8
13.10 1.0.0 (main) v3.11.0
14.04LTS 1.0.7 (main) v3.13.0
14.10 1.1.0 (main) v3.16
15.04 1.1.0 (main) v3.18.2
参考: https://launchpad.net/lxc/+packages
LXCの歴史
● Upstream project
○ https://github.com/lxc/lxc
3. LXCの特徴と利点
LXCの特徴と利点
LXCの利点
● 起動が早い
○ init以降の処理のみ
● ハードウエアエミュレーションでは無い。
○ コンテナとホストで同じカーネルを共有。
○ 高集約
■ CPU, Disk I/O, Network I/Oのオーバヘッドが無い。
● 省電力、省スペース
● コンテナのrootがホストOS上では特権を持たない
LXCの特徴と利点
LXCの制約
● コンテナがホストOSのカーネル内部で動くので、コンテナ毎に異なる
カーネルを持てない。
● コンテナとしてLinuxのみ対応
4. LXCの仕組み
● Linuxカーネルの標準機能を使い、コンテナ間
の隔離を実装
○ Namespace: コンテナごとのリソース管理
テーブル
○ Cgroup: システムリソース(cpu, blkio,
net_cls等)の制御
LXCの仕組み
LXCの仕組み - namespace
● Namespace
○ プロセスに対して、リソースを区切って、 それだけしか見せないため
のもの。
○ 各プロセスのNamespaceは、” /proc/<PID>/ns”を見ると、なんとな
くイメージがつきます。
root@ip-172-30-0-74:/# ls -l /proc/948/ns/
total 0
lrwxrwxrwx 1 root root 0 Feb 1 15:25 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 Feb 1 15:25 mnt -> mnt:[4026531840]
lrwxrwxrwx 1 root root 0 Feb 1 15:25 net -> net:[4026531992]
lrwxrwxrwx 1 root root 0 Feb 1 15:25 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 Feb 1 15:25 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 Feb 1 15:25 uts -> uts:[4026531838]
LXCの仕組み - namespace
● Mount Namespace
○ マウントに関するNamespace
# unshare --mount /bin/bash
# mkdir /hoge
# mount -t tmpfs tmpfs /hoge
# touch /hoge/a.txt
# mkdir /hoge/fuga
# ls /hoge
a.txt fuga
# 別のシェルから
ubuntu@ip-172-30-0-74:~$ ls -l /hoge
total 0
LXCの仕組み - namespace
● Network Namespace
○ ネットワークに関するNamespace
ubuntu@ip-172-30-0-74:~$ ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP mode
DEFAULT group default qlen 1000 link/ether 06:ce:5f:ee:a3:3b brd ff:ff:ff:ff:ff:ff
3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
mode DEFAULT group default link/ether 16:f9:d9:2e:af:28 brd ff:ff:ff:ff:ff:ff
ubuntu@ip-172-30-0-74:~$ sudo ip netns add hoge
ubuntu@ip-172-30-0-74:~$ ip netns
hoge
ubuntu@ip-172-30-0-74:~$ sudo ip netns exec hoge /bin/bash
root@ip-172-30-0-74:~# ip link list
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
LXCの仕組み - namespace
● UTS Namespace
○ ホスト名/ドメイン名のNamespace
ubuntu@ip-172-30-0-74:~$ hostname
ip-172-30-0-74
ubuntu@ip-172-30-0-74:~$ sudo unshare --uts /bin/bash
root@ip-172-30-0-74:~# hostname
ip-172-30-0-74
root@ip-172-30-0-74:~# hostname hoge
root@ip-172-30-0-74:~# hostname
hoge
root@ip-172-30-0-74:~# exit
exit
ubuntu@ip-172-30-0-74:~$ hostname
ip-172-30-0-74
LXCの仕組み - namespace
● IPC Namespace
○ 共有メモリやセマフォなどのNamespace
ubuntu@ip-172-30-0-74:~$ ipcmk -M 256
Shared memory id: 0
ubuntu@ip-172-30-0-74:~$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x62d56f82 0 ubuntu 644 256 0
ubuntu@ip-172-30-0-74:~$ sudo unshare --ipc /bin/bash
root@ip-172-30-0-74:~# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
LXCの仕組み - namespace
● PID Namespace
○ http://man7.org/linux/man-pages/man1/unshare.1.html
# 14.04のutil-linuxパッケージ(ver 2.20.1)ではサポートされていないオプションなので、 2.24.1をビルドして使い
ました。
root@ip-172-30-0-74:/tmp/util-linux-2.24.1# readlink /proc/self
32368
root@ip-172-30-0-74:/tmp/util-linux-2.24.1# ./unshare --fork --pid --mount-proc
readlink /proc/self
1
LXCの仕組み - namespace
● UID Namespace
○ http://man7.org/linux/man-pages/man1/unshare.1.html
# 14.04のutil-linuxパッケージ(ver 2.20.1)ではサポートされていないオプションなので、 2.24.1をビルドして使いました。
ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ id
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24
(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),102(netdev)
ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ ./unshare --user
nobody@ip-172-30-0-74:/tmp/util-linux-2.24.1$ id
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
LXCの仕組み - cgroup
● Cgroup (Control Group)
○ プロセスのグループ化。
○ グループに対して共通のリソース管理を行う。
■ 例. コンテナがホストのリソースを食いつくして,ホストや他コンテ
ナに影響を与えないようにする。
○ cgroupは仮想的なファイルシステムとして操作
■ /proc以下のファイルみたいな感じ。
LXCの仕組み - cgroup
● Cgroup (Control Group)
○ ”/sys/fs/cgroup”にマウントされてる(いた)
○ 14.04LTSから、cgmanagerで管理されてます。
○ 14.04LTSでcgroupfsを直接触るには、ちょっと工夫が必要。
■ 別のマウント名前空間内で マウントされてるので。
参考: http://askubuntu.com/questions/439056/why-there-is-no-nsenter-in-util-linux
$ wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -qO - |
tar -xz -C /tmp
$ sudo apt-get install libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev
debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool
$ ./autogen.sh
$ ./configure && make
$ sudo ./nsenter -t `pgrep cgmanager` --mount
LXCの仕組み - cgroup
● Cgroup (Control Group)
○ 例. メモリ消費量の制限値
root@ip-172-30-0-74:/run/cgmanager/fs/memory# ls
cgroup.clone_children memory.limit_in_bytes
cgroup.event_control memory.max_usage_in_bytes
…(snip)...
memory.kmem.tcp.usage_in_bytes tasks
memory.kmem.usage_in_bytes
root@ip-172-30-0-74:/run/cgmanager/fs/memory# less tasks
1
2
...(snip)...
5149
5155
root@ip-172-30-0-74:/run/cgmanager/fs/memory# cat memory.limit_in_bytes
18446744073709551615
LXCの仕組み - cgroup
● Cgmanager (Control Group Manager)
○ 14.04LTSから導入。
○ /sys/fs/cgroup/cgmanagerには、ソケットがあるのみ。
$ ls -l /sys/fs/cgroup/cgmanager
total 0
srwxrwxrwx 1 root root 0 Feb 1 15:05 sock
$ file /sys/fs/cgroup/cgmanager/sock
/sys/fs/cgroup/cgmanager/sock: socket
LXCの仕組み - cgroup
● Cgmanager (Control Group Manager)
○ /run/cgmanager/fsのディレクトリは空(マウントされてないように見え
る)
■ 別のマウント名前空間内で マウントされてるので。
ubuntu@ip-172-30-0-74:~$ ls -l /run/cgmanager/fs
total 0
drwxr-xr-x 2 root root 40 Feb 1 15:05 blkio
drwxr-xr-x 2 root root 40 Feb 1 15:05 cpu
drwxr-xr-x 2 root root 40 Feb 1 15:05 cpuacct
drwxr-xr-x 2 root root 40 Feb 1 15:05 cpuset
drwxr-xr-x 2 root root 40 Feb 1 15:05 devices
drwxr-xr-x 2 root root 40 Feb 1 15:05 freezer
drwxr-xr-x 2 root root 40 Feb 1 15:05 hugetlb
drwxr-xr-x 2 root root 40 Feb 1 15:05 memory
drwxr-xr-x 2 root root 40 Feb 1 15:05 none,name=systemd
drwxr-xr-x 2 root root 40 Feb 1 15:05 perf_event
ubuntu@ip-172-30-0-74:~$ ls -l /run/cgmanager/fs/memory/
total 0
LXCの仕組み - cgroup
● Cgmanager (Control Group Manager)
○ /run/cgmanager/fsのディレクトリは空(マウントされてないように見え
る)
ubuntu@ip-172-30-0-74:~$ sudo ls -l /proc/1/ns/mnt
lrwxrwxrwx 1 root root 0 Feb 5 10:06 /proc/1/ns/mnt -> mnt:[4026531840]
ubuntu@ip-172-30-0-74:~$ ps
PID TTY TIME CMD
2074 pts/1 00:00:00 bash
2493 pts/1 00:00:00 ps
ubuntu@ip-172-30-0-74:~$ ls -l /proc/2074/ns/mnt
lrwxrwxrwx 1 ubuntu ubuntu 0 Feb 5 10:07 /proc/2074/ns/mnt -> mnt:[4026531840]
ubuntu@ip-172-30-0-74:~$ pgrep cgmanager
3636
ubuntu@ip-172-30-0-74:~$ sudo ls -l /proc/3636/ns/mnt
lrwxrwxrwx 1 root root 0 Feb 1 16:41 /proc/3636/ns/mnt -> mnt:[4026532163]
LXCの仕組み
● LXCプロセスの様子
○ pstree -p
○ コンテナ側
# pstreeをインストール
$ apt-cache search pstree
$ sudo apt-get update
$ sudo apt-get install psmisc
root@u1:~# pstree -p
init(1)-+-cron(372)
|-dhclient(294)
|-getty(360)
|-getty(362)
|-getty(363)
|-getty(407)
|-getty(442)
|-rsyslogd(254)-+-{rsyslogd}(255)
| |-{rsyslogd}(256)
| `-{rsyslogd}(257)
|-systemd-udevd(190)
…(snip)....
LXCの仕組み
● LXCプロセスの様子
○ pstree -p
○ ホスト側
ubuntu@ip-172-30-0-74:~$ pstree -p
init(1)-+-acpid(1122)
...(snip)...
|-sshd(1121)-+-sshd(2651)---sshd(2726)---bash(2727)---sudo(3647)---lxc-start(3648)---init(3656)-+-cron(4066)
| | |-dhclient(3988)
| | |-getty(4054)
| | |-getty(4056)
| | |-getty(4057)
| | |-getty(4101)
| | |-getty(4260)
| | |-rsyslogd(3948)-+-{rsyslogd}(3949)
| | | |-{rsyslogd}(3950)
| | | `-{rsyslogd}(3951)
| | |-systemd-udevd(3882)
| | |-upstart-file-br(3957)
| | |-upstart-socket-(3954)
| | `-upstart-udev-br(3870)
| `-sshd(4136)---sshd(4211)---bash(4212)---pstree(4361)
...(snip)...
LXCの仕組み
● ネットワークの様子
○ ip addr show
○ ホスト側
root@ip-172-30-0-74:/var/lib/lxc/u1# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
…(省略)...
3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether fe:37:55:65:2e:d8 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
valid_lft forever preferred_lft forever
inet6 fe80::14f9:d9ff:fe2e:af28/64 scope link
valid_lft forever preferred_lft forever
5: vethXG4556: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master lxcbr0 state UP group
default qlen 1000
link/ether fe:37:55:65:2e:d8 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc37:55ff:fe65:2ed8/64 scope link
valid_lft forever preferred_lft forever
LXCの仕組み
● ネットワークの様子
○ ip addr show
○ ホスト側
# pgrep init
1
3656
# ls -l /proc/3656/ns/net
lrwxrwxrwx 1 root root 0 Feb 5 14:26 /proc/3656/ns/net -> net:[4026532175]
# ls -l /proc/1/ns/net
lrwxrwxrwx 1 root root 0 Feb 5 10:06 /proc/1/ns/net -> net:[4026531992]
ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ sudo ./nsenter -t 3656 --net
root@ip-172-30-0-74:/tmp/util-linux-2.24.1# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
…(snip)...
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:16:3e:85:da:14 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.16/24 brd 10.0.3.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe85:da14/64 scope link
valid_lft forever preferred_lft forever
LXCの仕組み
● ネットワークの様子
○ ip addr show
○ コンテナ側
root@u1:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:16:3e:85:da:14 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.16/24 brd 10.0.3.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe85:da14/64 scope link
valid_lft forever preferred_lft forever
LXCの仕組み (オマケ - chroot)
● chroot
○ ルートディレクトリが指定されたディレクトリになり、上位ディレクトリに
はアクセスできない。
○ プログラムが動作するのに必要なコマンドやライブラリが、chrootされ
た環境中に存在する必要がある。
# mkdir -p /chroot/a
# cp -pR /bin /sbin /lib /lib64 /usr /var /etc /chroot/a/
# cd /chroot/a
# mkdir proc sys dev
# mount -t proc proc proc/
# mount -t sysfs sys sys/
# mount -o bind /dev dev/
# chroot /chroot/a /bin/bash
LXCの仕組み (オマケ - chroot)
● chroot
○ chrootの内部・外部で、同じプロセスリストが見える。ユーザーIDや
ネットワークインターフェイスも共通
# ps -ef (chrootの外で)
root@ip-172-30-0-74:~# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 14:34 ? 00:00:01 /sbin/init
root 2 0 0 14:34 ? 00:00:00 [kthreadd]
root 3 2 0 14:34 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 14:34 ? 00:00:00 [kworker/0:0H]
root 6 2 0 14:34 ? 00:00:00 [kworker/u30:0]
root 7 2 0 14:34 ? 00:00:00 [rcu_sched]
root 8 2 0 14:34 ? 00:00:00 [rcuos/0]
…(省略)...
LXCの仕組み (オマケ - chroot)
● chroot
○ chrootの内部・外部で、同じプロセスリストが見える。ユーザーIDや
ネットワークインターフェイスも共通
# ps -ef (chrootの内で)
root@ip-172-30-0-74:~# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 14:34 ? 00:00:01 /sbin/init
root 2 0 0 14:34 ? 00:00:00 [kthreadd]
root 3 2 0 14:34 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 14:34 ? 00:00:00 [kworker/0:0H]
root 6 2 0 14:34 ? 00:00:00 [kworker/u30:0]
root 7 2 0 14:34 ? 00:00:00 [rcu_sched]
root 8 2 0 14:34 ? 00:00:00 [rcuos/0]
…(省略)...
LXCの仕組み (オマケ - FreeBSD Jail)
● FreeBSD Jail
○ FreeBSD 10.1 のAMI(ami-e1d5ede0)がコミュニティから出ているの
で使わせて頂くことに。
○ ユーザ名は、”ec2-user”
○ t2.microのEBSだと、デフォルトが、10Gなので、cpの途中でディスク
容量不足になります。
$ su - root
# mkdir -p /jail/
# cp -Rp /bin /sbin /lib /libexec /usr /var /etc /jail
# mkdir /jail/dev
# mount -t devfs devfs /jail/dev
# jail -c name=a path=/jail command=/bin/tcsh
LXCの仕組み (オマケ - FreeBSD Jail)
● FreeBSD Jail
○ Jailの内外で違うプロセスリストが見える。
Jailの外で
root@ip-172-30-0-17:/ # pwd
/
root@ip-172-30-0-17:/ # ls
.cshrc .snap boot etc lib mnt root tmp
.profile COPYRIGHT dev home libexec proc sbin usr
.rnd bin entropy jail media rescue sys var
root@ip-172-30-0-17:~ # ps -auxww
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 11 100.0 0.0 0 16 - RL 12:45PM 146:46.18 [idle]
root 0 0.0 0.0 0 160 - DLs 12:45PM 0:00.01 [kernel]
root 1 0.0 0.0 9472 416 - ILs 12:45PM 0:00.00 /sbin/init --
root 2 0.0 0.0 0 32 - DL 12:45PM 0:00.00 [cam]
root 3 0.0 0.0 0 16 - DL 12:45PM 0:00.00 [balloon]
root 4 0.0 0.0 0 16 - DL 12:45PM 0:00.00 [sctp_iterator]
...(省略)...
LXCの仕組み (オマケ - FreeBSD Jail)
● FreeBSD Jail
○ Jailの内外で違うプロセスリストが見える。
Jailの内で
root@ip-172-30-0-17:/ # pwd
/
root@ip-172-30-0-17:/ # ls
bin dev etc lib libexec sbin usr var
root@ip-172-30-0-17:/ # ps -auxww
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 971 0.0 0.3 23572 3364 0 SJ 3:13PM 0:00.00 /bin/tcsh
root 975 0.0 0.2 18736 2232 0 R+J 3:13PM 0:00.00 ps -auxww
Hands-on session
オマケ① JujuでLXC
JujuでLXC
● インストール
$ sudo apt-get install software-properties-common
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:juju/stable
$ sudo apt-get update
$ sudo apt-get install juju-local
● 設定
$ juju generate-config
$ juju switch local
● Jujuでワークロードデプロイ
$ juju bootstrap
$ juju deploy juju-gui
$ juju deploy wordpress
$ juju deploy mysql
$ juju add-relation mysql wordpress
$ juju stat
JujuでLXC
● bundle.yamlで物理マシン、LXCの混在環境
test-selab:
series: trusty
services:
ubuntu:
charm: cs:trusty/ubuntu-0
constraints: tags=test
rabbitmq-server:
charm: cs:trusty/rabbitmq-server-7
to: lxc:ubuntu=0
postgresql:
charm: cs:trusty/postgresql-3
constraints: mem=2048
to: lxc:ubuntu=0
options:
extra-packages: python-apt postgresql-contrib postgresql-.*-debversion
max_connections: 500
haproxy:
charm: cs:trusty/haproxy-1
to: lxc:ubuntu=0
…(省略)...
オマケ② LXD (lex-dee)紹介
LXD (lex-dee)紹介
http://blog.dustinkirkland.com/2014/11/where-
were-going-with-lxd.html
Docker is not a hypervisor
It is an application distribution mechanism...
And it is fantastic at that!
We are introducing a new hypervisor
Full system containers
bare metal performance
with the experience of a VM
Security
User Namespaces
cgroups
SECCOMP
AppArmor
Hardware Assist
Live Migration
Smooth, fast, reliable
Density
Less overhead ⇒ more instances
Operational efficiency
Performance
Native hardware equivalence
lxd
Persistent management daemon
lxd
REST API over network or local socket
lxd
More powerful, graceful CLI
lxd
Snapshot, checkpoint, migrate, restart
lxd
Secure, by default
lxd
Dynamic, extensible storage and networking
lxd
Implemented in Go
nova-compute-flex
Tech preview in Ubuntu OpenStack Juno
nova-compute-flex
Schedules instances in Nova as full system
containers
nova-compute-flex
Boots images from Glance
nova-compute-flex
Communicates via Neutron
nova-compute-flex
Will utilize storage from Swift/Cinder/Ceph

More Related Content

What's hot

Trema での Open vSwitch
Trema での Open vSwitchTrema での Open vSwitch
Trema での Open vSwitch
kazuyas
 
Open vSwitchソースコードの全体像
Open vSwitchソースコードの全体像 Open vSwitchソースコードの全体像
Open vSwitchソースコードの全体像
Sho Shimizu
 
現場で役に立たないsudoの使い方
現場で役に立たないsudoの使い方現場で役に立たないsudoの使い方
現場で役に立たないsudoの使い方
(^-^) togakushi
 

What's hot (20)

Lagopus 0.2.2
Lagopus 0.2.2Lagopus 0.2.2
Lagopus 0.2.2
 
Lagopus 0.2
Lagopus 0.2Lagopus 0.2
Lagopus 0.2
 
Trema での Open vSwitch
Trema での Open vSwitchTrema での Open vSwitch
Trema での Open vSwitch
 
Open vSwitchソースコードの全体像
Open vSwitchソースコードの全体像 Open vSwitchソースコードの全体像
Open vSwitchソースコードの全体像
 
あるキャッシュメモリの話
あるキャッシュメモリの話あるキャッシュメモリの話
あるキャッシュメモリの話
 
Linux Namespaces
Linux NamespacesLinux Namespaces
Linux Namespaces
 
StackExchangeで見たシステムプログラミング案件
StackExchangeで見たシステムプログラミング案件StackExchangeで見たシステムプログラミング案件
StackExchangeで見たシステムプログラミング案件
 
Lxc cf201207-presen
Lxc cf201207-presenLxc cf201207-presen
Lxc cf201207-presen
 
Lagopus, raw socket build
Lagopus, raw socket buildLagopus, raw socket build
Lagopus, raw socket build
 
2021 10-12.linx device-tree
2021 10-12.linx device-tree2021 10-12.linx device-tree
2021 10-12.linx device-tree
 
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
2014年の社内新人教育テキスト #2(関数型言語からオブジェクト指向言語へ)
 
Mastodonインスタンスをセットアップできるスタートアップスクリプトについて
MastodonインスタンスをセットアップできるスタートアップスクリプトについてMastodonインスタンスをセットアップできるスタートアップスクリプトについて
Mastodonインスタンスをセットアップできるスタートアップスクリプトについて
 
パケットジェネレータipgenから見るnetmap
パケットジェネレータipgenから見るnetmapパケットジェネレータipgenから見るnetmap
パケットジェネレータipgenから見るnetmap
 
initramfsについて
initramfsについてinitramfsについて
initramfsについて
 
httpd.conf line 1 to 7, 24
httpd.conf line 1 to 7, 24httpd.conf line 1 to 7, 24
httpd.conf line 1 to 7, 24
 
FreeBSD jail+vnetと戯れた話
FreeBSD jail+vnetと戯れた話FreeBSD jail+vnetと戯れた話
FreeBSD jail+vnetと戯れた話
 
現場で役に立たないsudoの使い方
現場で役に立たないsudoの使い方現場で役に立たないsudoの使い方
現場で役に立たないsudoの使い方
 
Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編
 
Xeon dとlagopusと、pktgen dpdk
Xeon dとlagopusと、pktgen dpdkXeon dとlagopusと、pktgen dpdk
Xeon dとlagopusと、pktgen dpdk
 
sshdのお話
sshdのお話sshdのお話
sshdのお話
 

Similar to Ubuntuで始めるコンテナ技術入門

Lvmを縮小してみた
Lvmを縮小してみたLvmを縮小してみた
Lvmを縮小してみた
koedoyoshida
 
Osc10do linux nextstep
Osc10do linux nextstepOsc10do linux nextstep
Osc10do linux nextstep
smokey monkey
 

Similar to Ubuntuで始めるコンテナ技術入門 (20)

Ubuntuとコンテナ技術 What is LXD? and Why? 2015-12-08
Ubuntuとコンテナ技術 What is LXD? and Why? 2015-12-08Ubuntuとコンテナ技術 What is LXD? and Why? 2015-12-08
Ubuntuとコンテナ技術 What is LXD? and Why? 2015-12-08
 
コンテナ情報交換会2
コンテナ情報交換会2コンテナ情報交換会2
コンテナ情報交換会2
 
C/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツール
 
A story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88kA story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88k
 
osoljp 2011.08
osoljp 2011.08osoljp 2011.08
osoljp 2011.08
 
Hack for Docker's Network
Hack for Docker's NetworkHack for Docker's Network
Hack for Docker's Network
 
Linux Performance Analysis in 15 minutes
Linux Performance Analysis in 15 minutesLinux Performance Analysis in 15 minutes
Linux Performance Analysis in 15 minutes
 
Docker最新動向2017秋+セキュリティの落とし穴
Docker最新動向2017秋+セキュリティの落とし穴Docker最新動向2017秋+セキュリティの落とし穴
Docker最新動向2017秋+セキュリティの落とし穴
 
20170124 linux basic_1
20170124 linux basic_120170124 linux basic_1
20170124 linux basic_1
 
Lvmを縮小してみた
Lvmを縮小してみたLvmを縮小してみた
Lvmを縮小してみた
 
about DakotagUI
about DakotagUIabout DakotagUI
about DakotagUI
 
OpenStackでも重要な役割を果たすPacemakerを知ろう!
OpenStackでも重要な役割を果たすPacemakerを知ろう!OpenStackでも重要な役割を果たすPacemakerを知ろう!
OpenStackでも重要な役割を果たすPacemakerを知ろう!
 
ふつうのLinuxプログラミング
ふつうのLinuxプログラミングふつうのLinuxプログラミング
ふつうのLinuxプログラミング
 
Dockerを支える技術
Dockerを支える技術Dockerを支える技術
Dockerを支える技術
 
Osc10do linux nextstep
Osc10do linux nextstepOsc10do linux nextstep
Osc10do linux nextstep
 
Open VZ
Open VZOpen VZ
Open VZ
 
Building production server on docker
Building production server on dockerBuilding production server on docker
Building production server on docker
 
Building production server on docker
Building production server on dockerBuilding production server on docker
Building production server on docker
 
SELinux_Updates_PoC_20170516
SELinux_Updates_PoC_20170516SELinux_Updates_PoC_20170516
SELinux_Updates_PoC_20170516
 
カーネルVm関西その参lt
カーネルVm関西その参ltカーネルVm関西その参lt
カーネルVm関西その参lt
 

Ubuntuで始めるコンテナ技術入門

  • 2. Agenda ● 1. コンテナ関連技術の歴史の振り返り ● 2. LXCの歴史 ● 3. LXCの特徴と利点 ● 4. LXCの仕組み ● ハンズオンセッション ● [オマケ①] JujuでLXC ● [オマケ②] LXD (lex-dee)紹介
  • 7. コンテナ技術の歴史 FreeBSD Jail 大雑把に言って、 ● プロセスリスト、ネットワークスタックも分離(隔 離) ● # ごめんなさい。不勉強です。 ユースケース/モチベーションは、 ● root権限を一般ユーザにも委譲 ● ホスティングサービス
  • 8. コンテナ技術の歴史 LXC 大雑把に言って、 ● 一通りのリソース管理テーブルを隔離 ● システムリソース(cpu, ディスク, メモリ等)の制御 ユースケース/モチベーションは、 ● 軽量仮想環境
  • 10. LXCの中核 ● Linuxカーネルの標準機能 ○ Namespace: コンテナごとのリソース管理 テーブル ○ Cgroup: システムリソース(cpu, blkio, net_cls等)の制御 徐々にLinuxカーネルに実装されてきて、カーネル 3.12くらいで、一通りの機能が実装。 LXCの歴史
  • 11. LXCの歴史 ● Namespaceの歴史 Namespace Linux kernel 隔離対象 Mount namespaces 2.4.19 ファイルシステムマウント UTS namespaces 2.6.19 ノード名、ドメイン名 IPC namespaces 2.6.19 IPC (interprocess communication) PID namespaces 2.6.24 プロセスID Network namespaces 2.6.29 ネットワークデバイス, IPアドレス, ルー ティングテーブル, /proc/net, ポート番 号, など User namespaces 3.8 UID, GID 参考: http://lwn.net/Articles/531114/
  • 12. LXCの歴史 ● Ubuntuとの関わり Ubuntu Version LXC version Kernel version 12.04LTS 0.7.5 (universe) v3.2.14 12.10 0.8.0 (universe) v3.5.5 13.04 0.9.0 (universe) v3.8.8 13.10 1.0.0 (main) v3.11.0 14.04LTS 1.0.7 (main) v3.13.0 14.10 1.1.0 (main) v3.16 15.04 1.1.0 (main) v3.18.2 参考: https://launchpad.net/lxc/+packages
  • 13. LXCの歴史 ● Upstream project ○ https://github.com/lxc/lxc
  • 15. LXCの特徴と利点 LXCの利点 ● 起動が早い ○ init以降の処理のみ ● ハードウエアエミュレーションでは無い。 ○ コンテナとホストで同じカーネルを共有。 ○ 高集約 ■ CPU, Disk I/O, Network I/Oのオーバヘッドが無い。 ● 省電力、省スペース ● コンテナのrootがホストOS上では特権を持たない
  • 18. ● Linuxカーネルの標準機能を使い、コンテナ間 の隔離を実装 ○ Namespace: コンテナごとのリソース管理 テーブル ○ Cgroup: システムリソース(cpu, blkio, net_cls等)の制御 LXCの仕組み
  • 19. LXCの仕組み - namespace ● Namespace ○ プロセスに対して、リソースを区切って、 それだけしか見せないため のもの。 ○ 各プロセスのNamespaceは、” /proc/<PID>/ns”を見ると、なんとな くイメージがつきます。 root@ip-172-30-0-74:/# ls -l /proc/948/ns/ total 0 lrwxrwxrwx 1 root root 0 Feb 1 15:25 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Feb 1 15:25 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Feb 1 15:25 net -> net:[4026531992] lrwxrwxrwx 1 root root 0 Feb 1 15:25 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Feb 1 15:25 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Feb 1 15:25 uts -> uts:[4026531838]
  • 20. LXCの仕組み - namespace ● Mount Namespace ○ マウントに関するNamespace # unshare --mount /bin/bash # mkdir /hoge # mount -t tmpfs tmpfs /hoge # touch /hoge/a.txt # mkdir /hoge/fuga # ls /hoge a.txt fuga # 別のシェルから ubuntu@ip-172-30-0-74:~$ ls -l /hoge total 0
  • 21. LXCの仕組み - namespace ● Network Namespace ○ ネットワークに関するNamespace ubuntu@ip-172-30-0-74:~$ ip link list 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 06:ce:5f:ee:a3:3b brd ff:ff:ff:ff:ff:ff 3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default link/ether 16:f9:d9:2e:af:28 brd ff:ff:ff:ff:ff:ff ubuntu@ip-172-30-0-74:~$ sudo ip netns add hoge ubuntu@ip-172-30-0-74:~$ ip netns hoge ubuntu@ip-172-30-0-74:~$ sudo ip netns exec hoge /bin/bash root@ip-172-30-0-74:~# ip link list 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  • 22. LXCの仕組み - namespace ● UTS Namespace ○ ホスト名/ドメイン名のNamespace ubuntu@ip-172-30-0-74:~$ hostname ip-172-30-0-74 ubuntu@ip-172-30-0-74:~$ sudo unshare --uts /bin/bash root@ip-172-30-0-74:~# hostname ip-172-30-0-74 root@ip-172-30-0-74:~# hostname hoge root@ip-172-30-0-74:~# hostname hoge root@ip-172-30-0-74:~# exit exit ubuntu@ip-172-30-0-74:~$ hostname ip-172-30-0-74
  • 23. LXCの仕組み - namespace ● IPC Namespace ○ 共有メモリやセマフォなどのNamespace ubuntu@ip-172-30-0-74:~$ ipcmk -M 256 Shared memory id: 0 ubuntu@ip-172-30-0-74:~$ ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x62d56f82 0 ubuntu 644 256 0 ubuntu@ip-172-30-0-74:~$ sudo unshare --ipc /bin/bash root@ip-172-30-0-74:~# ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status
  • 24. LXCの仕組み - namespace ● PID Namespace ○ http://man7.org/linux/man-pages/man1/unshare.1.html # 14.04のutil-linuxパッケージ(ver 2.20.1)ではサポートされていないオプションなので、 2.24.1をビルドして使い ました。 root@ip-172-30-0-74:/tmp/util-linux-2.24.1# readlink /proc/self 32368 root@ip-172-30-0-74:/tmp/util-linux-2.24.1# ./unshare --fork --pid --mount-proc readlink /proc/self 1
  • 25. LXCの仕組み - namespace ● UID Namespace ○ http://man7.org/linux/man-pages/man1/unshare.1.html # 14.04のutil-linuxパッケージ(ver 2.20.1)ではサポートされていないオプションなので、 2.24.1をビルドして使いました。 ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ id uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24 (cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),102(netdev) ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ ./unshare --user nobody@ip-172-30-0-74:/tmp/util-linux-2.24.1$ id uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
  • 26. LXCの仕組み - cgroup ● Cgroup (Control Group) ○ プロセスのグループ化。 ○ グループに対して共通のリソース管理を行う。 ■ 例. コンテナがホストのリソースを食いつくして,ホストや他コンテ ナに影響を与えないようにする。 ○ cgroupは仮想的なファイルシステムとして操作 ■ /proc以下のファイルみたいな感じ。
  • 27. LXCの仕組み - cgroup ● Cgroup (Control Group) ○ ”/sys/fs/cgroup”にマウントされてる(いた) ○ 14.04LTSから、cgmanagerで管理されてます。 ○ 14.04LTSでcgroupfsを直接触るには、ちょっと工夫が必要。 ■ 別のマウント名前空間内で マウントされてるので。 参考: http://askubuntu.com/questions/439056/why-there-is-no-nsenter-in-util-linux $ wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -qO - | tar -xz -C /tmp $ sudo apt-get install libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool $ ./autogen.sh $ ./configure && make $ sudo ./nsenter -t `pgrep cgmanager` --mount
  • 28. LXCの仕組み - cgroup ● Cgroup (Control Group) ○ 例. メモリ消費量の制限値 root@ip-172-30-0-74:/run/cgmanager/fs/memory# ls cgroup.clone_children memory.limit_in_bytes cgroup.event_control memory.max_usage_in_bytes …(snip)... memory.kmem.tcp.usage_in_bytes tasks memory.kmem.usage_in_bytes root@ip-172-30-0-74:/run/cgmanager/fs/memory# less tasks 1 2 ...(snip)... 5149 5155 root@ip-172-30-0-74:/run/cgmanager/fs/memory# cat memory.limit_in_bytes 18446744073709551615
  • 29. LXCの仕組み - cgroup ● Cgmanager (Control Group Manager) ○ 14.04LTSから導入。 ○ /sys/fs/cgroup/cgmanagerには、ソケットがあるのみ。 $ ls -l /sys/fs/cgroup/cgmanager total 0 srwxrwxrwx 1 root root 0 Feb 1 15:05 sock $ file /sys/fs/cgroup/cgmanager/sock /sys/fs/cgroup/cgmanager/sock: socket
  • 30. LXCの仕組み - cgroup ● Cgmanager (Control Group Manager) ○ /run/cgmanager/fsのディレクトリは空(マウントされてないように見え る) ■ 別のマウント名前空間内で マウントされてるので。 ubuntu@ip-172-30-0-74:~$ ls -l /run/cgmanager/fs total 0 drwxr-xr-x 2 root root 40 Feb 1 15:05 blkio drwxr-xr-x 2 root root 40 Feb 1 15:05 cpu drwxr-xr-x 2 root root 40 Feb 1 15:05 cpuacct drwxr-xr-x 2 root root 40 Feb 1 15:05 cpuset drwxr-xr-x 2 root root 40 Feb 1 15:05 devices drwxr-xr-x 2 root root 40 Feb 1 15:05 freezer drwxr-xr-x 2 root root 40 Feb 1 15:05 hugetlb drwxr-xr-x 2 root root 40 Feb 1 15:05 memory drwxr-xr-x 2 root root 40 Feb 1 15:05 none,name=systemd drwxr-xr-x 2 root root 40 Feb 1 15:05 perf_event ubuntu@ip-172-30-0-74:~$ ls -l /run/cgmanager/fs/memory/ total 0
  • 31. LXCの仕組み - cgroup ● Cgmanager (Control Group Manager) ○ /run/cgmanager/fsのディレクトリは空(マウントされてないように見え る) ubuntu@ip-172-30-0-74:~$ sudo ls -l /proc/1/ns/mnt lrwxrwxrwx 1 root root 0 Feb 5 10:06 /proc/1/ns/mnt -> mnt:[4026531840] ubuntu@ip-172-30-0-74:~$ ps PID TTY TIME CMD 2074 pts/1 00:00:00 bash 2493 pts/1 00:00:00 ps ubuntu@ip-172-30-0-74:~$ ls -l /proc/2074/ns/mnt lrwxrwxrwx 1 ubuntu ubuntu 0 Feb 5 10:07 /proc/2074/ns/mnt -> mnt:[4026531840] ubuntu@ip-172-30-0-74:~$ pgrep cgmanager 3636 ubuntu@ip-172-30-0-74:~$ sudo ls -l /proc/3636/ns/mnt lrwxrwxrwx 1 root root 0 Feb 1 16:41 /proc/3636/ns/mnt -> mnt:[4026532163]
  • 32. LXCの仕組み ● LXCプロセスの様子 ○ pstree -p ○ コンテナ側 # pstreeをインストール $ apt-cache search pstree $ sudo apt-get update $ sudo apt-get install psmisc root@u1:~# pstree -p init(1)-+-cron(372) |-dhclient(294) |-getty(360) |-getty(362) |-getty(363) |-getty(407) |-getty(442) |-rsyslogd(254)-+-{rsyslogd}(255) | |-{rsyslogd}(256) | `-{rsyslogd}(257) |-systemd-udevd(190) …(snip)....
  • 33. LXCの仕組み ● LXCプロセスの様子 ○ pstree -p ○ ホスト側 ubuntu@ip-172-30-0-74:~$ pstree -p init(1)-+-acpid(1122) ...(snip)... |-sshd(1121)-+-sshd(2651)---sshd(2726)---bash(2727)---sudo(3647)---lxc-start(3648)---init(3656)-+-cron(4066) | | |-dhclient(3988) | | |-getty(4054) | | |-getty(4056) | | |-getty(4057) | | |-getty(4101) | | |-getty(4260) | | |-rsyslogd(3948)-+-{rsyslogd}(3949) | | | |-{rsyslogd}(3950) | | | `-{rsyslogd}(3951) | | |-systemd-udevd(3882) | | |-upstart-file-br(3957) | | |-upstart-socket-(3954) | | `-upstart-udev-br(3870) | `-sshd(4136)---sshd(4211)---bash(4212)---pstree(4361) ...(snip)...
  • 34. LXCの仕組み ● ネットワークの様子 ○ ip addr show ○ ホスト側 root@ip-172-30-0-74:/var/lib/lxc/u1# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever …(省略)... 3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether fe:37:55:65:2e:d8 brd ff:ff:ff:ff:ff:ff inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0 valid_lft forever preferred_lft forever inet6 fe80::14f9:d9ff:fe2e:af28/64 scope link valid_lft forever preferred_lft forever 5: vethXG4556: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master lxcbr0 state UP group default qlen 1000 link/ether fe:37:55:65:2e:d8 brd ff:ff:ff:ff:ff:ff inet6 fe80::fc37:55ff:fe65:2ed8/64 scope link valid_lft forever preferred_lft forever
  • 35. LXCの仕組み ● ネットワークの様子 ○ ip addr show ○ ホスト側 # pgrep init 1 3656 # ls -l /proc/3656/ns/net lrwxrwxrwx 1 root root 0 Feb 5 14:26 /proc/3656/ns/net -> net:[4026532175] # ls -l /proc/1/ns/net lrwxrwxrwx 1 root root 0 Feb 5 10:06 /proc/1/ns/net -> net:[4026531992] ubuntu@ip-172-30-0-74:/tmp/util-linux-2.24.1$ sudo ./nsenter -t 3656 --net root@ip-172-30-0-74:/tmp/util-linux-2.24.1# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default …(snip)... 4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:16:3e:85:da:14 brd ff:ff:ff:ff:ff:ff inet 10.0.3.16/24 brd 10.0.3.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::216:3eff:fe85:da14/64 scope link valid_lft forever preferred_lft forever
  • 36. LXCの仕組み ● ネットワークの様子 ○ ip addr show ○ コンテナ側 root@u1:~# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:16:3e:85:da:14 brd ff:ff:ff:ff:ff:ff inet 10.0.3.16/24 brd 10.0.3.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::216:3eff:fe85:da14/64 scope link valid_lft forever preferred_lft forever
  • 37. LXCの仕組み (オマケ - chroot) ● chroot ○ ルートディレクトリが指定されたディレクトリになり、上位ディレクトリに はアクセスできない。 ○ プログラムが動作するのに必要なコマンドやライブラリが、chrootされ た環境中に存在する必要がある。 # mkdir -p /chroot/a # cp -pR /bin /sbin /lib /lib64 /usr /var /etc /chroot/a/ # cd /chroot/a # mkdir proc sys dev # mount -t proc proc proc/ # mount -t sysfs sys sys/ # mount -o bind /dev dev/ # chroot /chroot/a /bin/bash
  • 38. LXCの仕組み (オマケ - chroot) ● chroot ○ chrootの内部・外部で、同じプロセスリストが見える。ユーザーIDや ネットワークインターフェイスも共通 # ps -ef (chrootの外で) root@ip-172-30-0-74:~# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 14:34 ? 00:00:01 /sbin/init root 2 0 0 14:34 ? 00:00:00 [kthreadd] root 3 2 0 14:34 ? 00:00:00 [ksoftirqd/0] root 5 2 0 14:34 ? 00:00:00 [kworker/0:0H] root 6 2 0 14:34 ? 00:00:00 [kworker/u30:0] root 7 2 0 14:34 ? 00:00:00 [rcu_sched] root 8 2 0 14:34 ? 00:00:00 [rcuos/0] …(省略)...
  • 39. LXCの仕組み (オマケ - chroot) ● chroot ○ chrootの内部・外部で、同じプロセスリストが見える。ユーザーIDや ネットワークインターフェイスも共通 # ps -ef (chrootの内で) root@ip-172-30-0-74:~# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 14:34 ? 00:00:01 /sbin/init root 2 0 0 14:34 ? 00:00:00 [kthreadd] root 3 2 0 14:34 ? 00:00:00 [ksoftirqd/0] root 5 2 0 14:34 ? 00:00:00 [kworker/0:0H] root 6 2 0 14:34 ? 00:00:00 [kworker/u30:0] root 7 2 0 14:34 ? 00:00:00 [rcu_sched] root 8 2 0 14:34 ? 00:00:00 [rcuos/0] …(省略)...
  • 40. LXCの仕組み (オマケ - FreeBSD Jail) ● FreeBSD Jail ○ FreeBSD 10.1 のAMI(ami-e1d5ede0)がコミュニティから出ているの で使わせて頂くことに。 ○ ユーザ名は、”ec2-user” ○ t2.microのEBSだと、デフォルトが、10Gなので、cpの途中でディスク 容量不足になります。 $ su - root # mkdir -p /jail/ # cp -Rp /bin /sbin /lib /libexec /usr /var /etc /jail # mkdir /jail/dev # mount -t devfs devfs /jail/dev # jail -c name=a path=/jail command=/bin/tcsh
  • 41. LXCの仕組み (オマケ - FreeBSD Jail) ● FreeBSD Jail ○ Jailの内外で違うプロセスリストが見える。 Jailの外で root@ip-172-30-0-17:/ # pwd / root@ip-172-30-0-17:/ # ls .cshrc .snap boot etc lib mnt root tmp .profile COPYRIGHT dev home libexec proc sbin usr .rnd bin entropy jail media rescue sys var root@ip-172-30-0-17:~ # ps -auxww USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root 11 100.0 0.0 0 16 - RL 12:45PM 146:46.18 [idle] root 0 0.0 0.0 0 160 - DLs 12:45PM 0:00.01 [kernel] root 1 0.0 0.0 9472 416 - ILs 12:45PM 0:00.00 /sbin/init -- root 2 0.0 0.0 0 32 - DL 12:45PM 0:00.00 [cam] root 3 0.0 0.0 0 16 - DL 12:45PM 0:00.00 [balloon] root 4 0.0 0.0 0 16 - DL 12:45PM 0:00.00 [sctp_iterator] ...(省略)...
  • 42. LXCの仕組み (オマケ - FreeBSD Jail) ● FreeBSD Jail ○ Jailの内外で違うプロセスリストが見える。 Jailの内で root@ip-172-30-0-17:/ # pwd / root@ip-172-30-0-17:/ # ls bin dev etc lib libexec sbin usr var root@ip-172-30-0-17:/ # ps -auxww USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root 971 0.0 0.3 23572 3364 0 SJ 3:13PM 0:00.00 /bin/tcsh root 975 0.0 0.2 18736 2232 0 R+J 3:13PM 0:00.00 ps -auxww
  • 45. JujuでLXC ● インストール $ sudo apt-get install software-properties-common $ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:juju/stable $ sudo apt-get update $ sudo apt-get install juju-local ● 設定 $ juju generate-config $ juju switch local ● Jujuでワークロードデプロイ $ juju bootstrap $ juju deploy juju-gui $ juju deploy wordpress $ juju deploy mysql $ juju add-relation mysql wordpress $ juju stat
  • 46. JujuでLXC ● bundle.yamlで物理マシン、LXCの混在環境 test-selab: series: trusty services: ubuntu: charm: cs:trusty/ubuntu-0 constraints: tags=test rabbitmq-server: charm: cs:trusty/rabbitmq-server-7 to: lxc:ubuntu=0 postgresql: charm: cs:trusty/postgresql-3 constraints: mem=2048 to: lxc:ubuntu=0 options: extra-packages: python-apt postgresql-contrib postgresql-.*-debversion max_connections: 500 haproxy: charm: cs:trusty/haproxy-1 to: lxc:ubuntu=0 …(省略)...
  • 49. Docker is not a hypervisor It is an application distribution mechanism... And it is fantastic at that!
  • 50. We are introducing a new hypervisor Full system containers bare metal performance with the experience of a VM
  • 53. Density Less overhead ⇒ more instances Operational efficiency
  • 56. lxd REST API over network or local socket
  • 62. nova-compute-flex Tech preview in Ubuntu OpenStack Juno
  • 63. nova-compute-flex Schedules instances in Nova as full system containers
  • 66. nova-compute-flex Will utilize storage from Swift/Cinder/Ceph