5. “I once heard that hypervisors
are the living proof of operating
system's incompetence”
-- Glauber Costa's - LinuxCon Europe 2012
@liuggio Giulio De Donato
6. ... containers ...
“I would love to say months,
but let's get realistic”
-- Glauber Costa's - LinuxCon Europe 2012
@liuggio Giulio De Donato
12. Let’s start with the first set of slides
Once upon a time ...
@liuggio Giulio De Donato
13. NAMESPACE
Linux 2.6.23 (released in late 2007)
6 namespaces
- mnt (mount points, filesystems)
- pid (processes)
- net (network stack)
- ipc (System V IPC)
- uts (hostname)
- user (UIDs)
Namespaces started in about
2002.
@liuggio Giulio De Donato
14. Namespaces processes API
consists of these 3 system calls:
● clone() - creates a new process and a new namespace; the
newly created process is attached to the new namespace
● unshare()–gets only a single parameter, flags. Does not create a
new process; creates a new namespace and attaches the calling
processto it.
● setns()- a new system call, for attaching the calling process to
an existing namespace;
@liuggio Giulio De Donato
17. CGroups!
The cgroup (control groups) subsystem is a Resource Management and Resource
Accounting/Tracking solution, providing a generic process - grouping framework
It handles resources such as memory, cpu, network, and more;
mostly needed in both ends of the spectrum (servers and embedded).
∎ Development was started by engineers at Google in 2006 under the name "process containers”
∎ Merged into kernel 2.6.24 (2008).
∎ cgroup core has 3 maintainers, and each cgroup controller has its own maintainer (cpu memory io)
@liuggio Giulio De Donato
24. Union File System
PRO
∎ File level
∎ No caches
CONS
∎ Bad performance for big files
∎ Not in kernel
∎ Too much layers costs
merge into a single directory 2 devices
Combining a large, read-only file system with small write area (like livecd)
@liuggio Giulio De Donato
25. ZFS is a combination of a volume manager (like LVM) and a filesystem (like ext4, xfs, or btrfs).
ZFS one of the most beloved features of Solaris, universally coveted by every Linux sysadmin with a Solaris background.
● snapshots
● copy-on-write cloning
● continuous integrity checking against data corruption
● automatic repair
● efficient data compression
2016
@liuggio Giulio De Donato
Sapete chi è lui? Facile
Crozza vs RAZZI
Esplogiamo la tecnologia e uccidiamo il magico
CTO
Golangit
Siamo nel 2016, e Docker è ovunque, nei workshop, nelle conferenze, nei blog che parlano di startup, tra i servizi di Amazon e dentro google app engine e kebernetes.
Gli ultimi anni sono stati grandiosi per i container ma sopratutto per Docker, si è addirittura definito uno standard di specifiche per la creazione dei container https://www.opencontainers.org/ (2015) sponsorizzato da Docker e mille altre aziende.
Giorni fa quando ho parlato del workshop su docker che ho tenuto, un ragazzo ha detto ah si la virtualizzazione, questa associazione tra virtualizzazione e container è concettualmente simile ma tecnicamente distante, molto distante…
sapremmo
Dare una definizione di cosa è un container, e da cosa è composto?
Mi piace l’idea che un container è una scatola in cui dentro viene eseguito uno o piu processi,
L’idea di questo blog post è proprio quella di esplodere la scatola e vedere come funziona un container esplicitando tutta la magia.
Sappiamo cosa fa… ma abbiamo mai pensato a cosa è
E da cosa è composto?
fight the magic non pensate che docker e che la tecnologia dei container sia troppo magica fa troppe cose...
Costa dice ti pare che un processo non puo’ girare in pace con un altri processi? Ti pare che c’è un concetto a cui linux non ha mai pensato?
ISOLATION
I sistemisti per permettere l’isolation aggiungono server fisici,
Poi è arrivato l’hypervisor, ma c’è qualcosa che ci siamo persi!
Costa dice ti pare che un processo non puo’ girare in pace con un altri processi? Ti pare che c’è un concetto a cui linux non ha mai pensato?
ISOLATION
I sistemisti per permettere l’isolation aggiungono server fisici,
Poi è arrivato l’hypervisor, ma c’è qualcosa che ci siamo persi!
The other side of the resource-allocation problem is denial-of-service attacks. With traditional UNIX systems, local denial-of-service attacks are relatively easy to perpetrate. As a first example, Glauber gave the following small script:
É possibile che due semplici script riescano a riempire il primo il filesystem e il secondo la ram?
Parliamo di come è composti un container dei 3 principali
Namespace isolamento astrazione
Cgroups isolamento come limitazione
Ufs. Isolamento nel FS ma anche altre funzionalità
..
Cerchiamo di far girare la giostra
fight the magic non pensate che docker e che la tecnologia dei container sia troppo magica fa troppe cose...
Saro’ breve
LXC owes its origin to the development of cgroups and namespaces in the Linux kernel to support lightweight virtualized OS environments (containers) and some early work by Daniel Lezcano and Serge Hallyn dating from 2009 at IBM
The LXC Project provides tools to manage containers, advanced networking and storage support and a wide choice of minimal container OS templates. It is currently led by a 2 member team, Stephane Graber and Serge Hallyn from Ubuntu. The LXC project is supported by Ubuntu.
LXC is actively developed but not well documented beyond Ubuntu. Cross distribution documentation is lacking, things usually work well in Ubuntu first, leaving to all round frustration and hair pulling for users of other distributions.
There is a lot of confusion, outdated and often just misleading information online. Add Docker to the mix which has aggressively marketed itself to the wider community (Ubuntu, why so quiet?) and the volume of information and scope for confusion has widened.
To clarify all the misconceptions both LXC an Docker are userland container managers that use kernel namespaces to provide end user containers. We also now have Systemd-Nspawn that does the same thing. The only difference is LXC containers have an an init and can thus run multiple processes and Docker containers do not have an init and can only run single processes.
LXC maintainer Stephane Graber's excellent 10 part Blog series on LXC 1.0 and our LXC Getting started guide provide an overview of LXC and its capabilities.
A process can be created in Linux by the fork(), clone()or vclone()system calls.
In order to support namespaces, 6 flags (CLONE_NEW*) were added. These flags (or a combination of them) can be used in clone()or unshare()system calls to create a namespace.
Namespaces API consists of these 3 system calls:
● clone() - creates a new process and a new namespace; the newly created process is attached to the new namespace.–The process creation and process termination methods, fork() and exit(), were patched to handle the new namespace CLONE_NEW* flags.
● unshare()–gets only a single parameter, flags.Does notcreate a new process; creates a new namespaceand attachesthe callingprocessto it.–unshare() was added in 2005.see “new system call, unshare” : http://lwn.net/Articles/135266/
● setns()-a new system call, for attaching the calling process to an existing namespace; prototype: intsetns(intfd, intnstype)
cd /home/liuggio/project/go/src/github.com/liuggio/c/namespace/noflag/sudo /usr/local/go/bin/go run namespace.go /bin/sh -c "hostname ciao;hostname"
$ df -h | grep "\/$"
/dev/sdb2 102G 85G 12G 88% /
$ df -h | grep "\/$" | awk '{print $1}'
/dev/sdb2
#scopriamo a quanto andiamo :)
$ dd if=/dev/zero of=`pwd`/file-xyz bs=1M count=500
$ dd if=/file-xyz of=/dev/null bs=1M count=300
$ lscgroup
300+0 records in
300+0 records out
314572800 bytes (315 MB) copied, 0,603292 s, 521 MB/s
$ ls /dev/sdb -l
brw-rw---- 1 root disk 8, 16feb 13 19:48 /dev/sdb
In the Linux Allocated Devices notation, 8:18 represents /dev/sdb
creiamo una cartella dentro cgroup da root :)
$ mkdir /sys/fs/cgroup/blkio/sponge; cd /sys/fs/cgroup/blkio/sponge
automaticamnete vengono creati dei file come per magia
diciamo che vogliamo limitare la lettura a 5mb al secondo
$ echo "8:16 5242880" > blkio.throttle.read_bps_device
puliamo la cache
$ echo 3 > /proc/sys/vm/drop_caches
$ free -m
$ cgexec -g blkio:sponge dd if=/file-xyz of=/dev/null & iotop
Partiamo dalle basi sapete cosa è
Eh no
Partiamo dalle basi dell’informatica
Se noi facessimo un giunto tra due rami dell’albero …
Union file systems, or UnionFS, are file systems that operate by creating layers, making them very lightweight and fast. Docker uses union file systems to provide the building blocks for containers. Docker can make use of several union file system variants including: AUFS, btrfs, vfs, and DeviceMapper.
Una funzionalità tanti benefici:
Siamo abituati a vedere l’albero del filesystem come alberi dove i figli sono cartelle separate unite solo dal padre
Connette l’albero filesystem in un unica cartella
Immagine!
Vantaggio della condivisione se aggiungo un layer dovro solo far scaricare il nuovo layer ai miei colleghi e non di nuovo tutta l’immagine.
velocità non in lettura ma nell’esecuzione e condivisione.
Quindi questa funzionalità permette anche ai container di avere una immagine su cui lavorare in readonly
Con la famosa read on write paragone con virtualbox copia prima e utilizzo dopo,
Write solo se serve.
2 features:
unione
copy on write
Union fs:
$ apt-get install aufs-tools
$ mkdir /tmp/dir1;
$ echo "ciao" >> /tmp/dir1/a
$ mkdir /tmp/aufs
$ mount -t aufs -o br=/tmp/dir1:`pwd` none /tmp/aufs
$ echo "miao" > /tmp/aufs/miao
$ ls -l /tmp/dir1; # c’è miao in dir2
$ ls -l /tmp/aufs; # c’è miao anche in dir1
$ ls -l `pwd`; # non c’è miao
$ mount -t aufs -o br="/tmp/a:`pwd`=rr:/tmp/b=rr" none /tmp/aufs
Per fare i layer ci vuole un albero union :)
https://docs.oracle.com/cd/E18752_01/html/817-5093/bkupsnapshot-9.html problemi per terabyte al reboot fa cose strane
Quindi siamo riusciti a far girare qualcosa
Ma non come riescono i professionisti.