l es con t en eurs s ous l in ux un État d e l '...

37
LES CONTENEURS SOUS LINUX LES CONTENEURS SOUS LINUX UN ÉTAT DE L'ART UN ÉTAT DE L'ART Grégory Colpart & Jérémy Lecour – VVT 2018

Upload: others

Post on 26-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LES CONTENEURS SOUS LINUXLES CONTENEURS SOUS LINUX UN ÉTAT DE L'ARTUN ÉTAT DE L'ART

Grégory Colpart & Jérémy Lecour – VVT 2018

Page 2: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

VISION SUBJECTIVEVISION SUBJECTIVE

Page 3: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

$ who Jérémy Lecour <[email protected]> Grégory Colpart <[email protected]> $ whois Evolix EVOLIX-AS : AS 197696 $ man Evolix Open Source managed hosting provider $ uptime up 14 years, 20 users $ whereis Evolix /fr/Marseille, /fr/Aix, /fr/Paris, /ca/Montréal $ top Linux/BSD servers: 800, customers: 120

Page 4: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

Infogérance / Hébergement dédié et cloud / Conseil et Formation

Sysadmins à Marseille et Montréal = 24/7

Linux, infra web, HA, virtualisation, conteneurs, Ansible

Clients : agences web, SaaS, médias

Page 5: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CONTEXTE / HISTORIQUECONTEXTE / HISTORIQUE

Page 6: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

VIRTUALISATIONVIRTUALISATIONVMWare, KVM, Xen, Virtualbox…

émulation du matériel

indépendance de l'OS virtualisé

para-virtualisation

Page 7: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

ISOLATION DE PROCESSUSISOLATION DE PROCESSUSenfermer le processus dans une prison (chroot)

accès limité au �lesystem

technique ancienne

OS/noyau homogène

Page 8: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CONTENEURSCONTENEURSutilisent les "namespaces"

partitionnement des ressources du Kernel

Page 9: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CARACTÉRISTIQUES ET TECHNOLOGIESCARACTÉRISTIQUES ET TECHNOLOGIES

Page 10: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

RÉSEAURÉSEAUNAT ou bridge

partage avec l'hôte

redirection de ports

Page 11: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

STOCKAGESTOCKAGEmontages classiques

accès au �lesystem de l'hôte

Page 12: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CGROUPSCGROUPSlimites de ressources

priorisation

mesure d'usage

contrôle d'exécution

Page 13: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CONTENEURS PRIVILÉGIÉS, OU NONCONTENEURS PRIVILÉGIÉS, OU NONprivilégié : accès total

non privilégié : accès limité

Page 14: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

TYPES DE CONTENEURSTYPES DE CONTENEURSsystème : init et arbre de processus

applicatif : un seul processus

Page 15: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LXCLXCLinuX Container

utilise les cgroups et namespaces

très facile à manipuler

Page 16: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CRÉATION D'UN CONTENEURCRÉATION D'UN CONTENEUR# apt-get install lxc # lxc-create --template download --name foo Setting up the GPG keyring Downloading the image index […] Distribution: debian Release: stretch Architecture: amd64 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created an Debian stretch amd64 (20180611_05:25) container. To enable SSH, run: apt install openssh-server No default root or user password are set by LXC.

Page 17: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LISTER, DÉMARRER, S'ATTACHER À UN CONTENEURLISTER, DÉMARRER, S'ATTACHER À UN CONTENEUR# lxc-ls foo # lxc-start --name foo # lxc-info --name foo # lxc-attach --name foo

Page 18: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

UNE VRAIE CONSOLE, SI BESOINUNE VRAIE CONSOLE, SI BESOIN# lxc-console --name foo Connected to tty 1 Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself Debian GNU/Linux buster/sid foo pts/0 foo login:

Page 19: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

UTILISATION DE SNAPSHOTSUTILISATION DE SNAPSHOTS# lxc-stop --name foo # lxc-snapshot --name foo # du -sch /var/lib/lxc/foo/snaps/snap0/ 354M /var/lib/lxc/foo/snaps/snap0/ # lxc-snapshot --name foo --list snap0 (/var/lib/lxc/foo/snaps) 2018:06:12 03:24:48 snap1 (/var/lib/lxc/foo/snaps) 2018:06:12 03:26:24 # lxc-snapshot --name foo --restore snap1

Page 20: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LIMITER LES RESSOURCES ALLOUÉES (À CHAUD)LIMITER LES RESSOURCES ALLOUÉES (À CHAUD)# lxc-cgroup --name foo cpuset.cpus 0 # lxc-cgroup --name foo memory.limit_in_bytes 4G

Page 21: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

CHACUN SES PROCESSUSCHACUN SES PROCESSUS# ps auwx root 1 […] /sbin/init root 5310 […] /sbin/init root 2658 […] /lib/systemd/systemd-journald root 389 […] /lib/systemd/systemd-journald root 1039 […] /lib/systemd/systemd-logind root 2704 […] /lib/systemd/systemd-logind systemd+ 2664 […] /lib/systemd/systemd-networkd systemd+ 2712 […] /lib/systemd/systemd-resolved systemd+ 719 […] /lib/systemd/systemd-timesyncd root 420 […] /lib/systemd/systemd-udevd message+ 1045 […] /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfilemessage+ 2698 […] /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile

Page 22: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

STOCKAGESTOCKAGEdir – stockage au sein d'un dossier classique

lvm – un volume logique par conteneur

btrfs, zfs – exploite les fonctionnalités natives

loop – une partition dédiée

rbd – un block-device Ceph

Page 23: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LXDLXDs'appuie sur LXC (liblxc)

simpli�e l'interface et les outils

fonctionnalités plus avancées

Page 24: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

FONCTIONNALITÉS MARQUANTESFONCTIONNALITÉS MARQUANTESDémon en Go avec API REST

Sécurisé par défaut

permet une gestion de cluster

https://linuxcontainers.org/lxd/try-it/

Page 25: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

DÉMO LXDDÉMO LXD# lxc list +------+---------+-----------------------+----------------------------------------------+| NAME | STATE | IPV4 | IPV6 +------+---------+-----------------------+----------------------------------------------+| toto | RUNNING | 10.219.150.156 (eth0) | 2001:470:b368:1070:216:3eff:fe96:da14 (eth0) +------+---------+-----------------------+----------------------------------------------+ # free -m total used free shared buff/cache available Mem: 256 26 70 189 158 229 # lxc config set toto limits.memory 128MB # lxc exec toto -- free -m total used free shared buff/cache available Mem: 128 5 89 189 33 122

Page 26: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

DOCKERDOCKERInitialement basé sur LXC

Orienté conteneurs applicatifs

fonctionnalités beaucoup plus avancées

Page 27: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

FONCTIONNALITÉS MARQUANTESFONCTIONNALITÉS MARQUANTESDémon en Go avec API REST

Gestion des images

Page 28: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

GESTION DES IMAGESGESTION DES IMAGESDocker�le

registry / Dockerhub

Orchestration

Page 29: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

DOCKERFILEDOCKERFILEFROM debian:stretch MAINTAINER Evolix ENV DEBIAN_FRONTEND noninteractive RUN apt-get update \ && apt-get install -y --no-install-recommends apache2 \ && rm -rf /var/lib/apt/lists/* ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

Page 30: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

# docker run debian:stretch Unable to find image 'debian:stretch' locally stretch: Pulling from library/debian cc1a78bfd46b: Pull complete Digest: sha256:de3eac... Status: Downloaded newer image for debian:stretch # docker images REPOSITORY TAG IMAGE ID CREATED SIZE debian stretch 8626492fecd3 7 weeks ago 101 MB # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f302ad884767 debian:stretch "bash" 5 minutes ago Exited (0) 5 minutes ago quirky_l

Page 31: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

DOCKERSDOCKERSdocker compose

Orchestration avec Swarm / Kubernetes

K8S… futur standard ?

Page 32: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

SURCOUCHESSURCOUCHES

Page 33: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

LIBVIRTLIBVIRTdémon de gestion d'hyperviseurs

KVM, Xen, VMWare, QEMU, LXC…

nombreux bindings (Python, Ruby, Perl…)

interfaces graphiques ou CLI

Page 34: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

VAGRANTVAGRANTautomate de gestion de VM

VirtualBox, VMWare, LXC, libvirt…

orienté "développeur"

facilite le provisionnement (Ansible…)

Page 35: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

SÉCURITÉSÉCURITÉséparation imparfaite

garder le contrôle des images

limiter les privilèges au maximum

Page 36: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

AU FINAL, LES CONTENEURSAU FINAL, LES CONTENEURSplus légers, performants, simples que des VM

de l'usage très basique à la plateforme complète

une histoire ancienne qui continue de s'écrire

Page 37: L ES CON T EN EURS S OUS L IN UX UN ÉTAT D E L ' ARTcesar.resinfo.org/IMG/pdf/08-vvt-2018.pdf · # apt-get install lxc # lxc-create --template download --name foo Setting up the

MERCIMERCI