Dec 10, 2018
Agenda
• Motivação
• LXC
• GO
• Dicas
• Perguntas e Respostas
Complexidade Atual
Complexidade atual (e crescendo)
CAOS
• Version spawn
• DEV / QA / Pre-Prod / Prod
• Continuos Integration
• Continuous Deployment
História
• Virtualização
• Servidores
• Rede
• Storage
• Aplicações – BINGO!!!
Virtualização de Servidores
• Benefícios amplamente conhecidos
• Mas....
– Tempo de provisionamento
– Quantidade de VM's
– Provisionamento Dinâmico
– HPC performance
– Burocracia interna
LXC – LinuX Containers
• Idéia não é nova : Jail / Zones / IBM / HP
Modelo Tradicional com
Máquina Virtual
LXC Style
LXC
• “Cgroups on steroids”
• Ligthweight
• Agilidade e Flexibilidade
• Compartimentação
• Open source / Custo
• Larga adoção
• HPC ready
• Cloud stlye
• Kernel Version
LXC
LXC
Kernel
Namespaces
Cgroups
chrootAppArmor
& SELinux
Seccomp
policies
LXC
Sistema Tunnable
blkio - Weighted proportional block I/O access. Group wide or per device.- Per device hard limits on block I/O read/write specified as bytes per second or IOPS
per second.
cpu - Time period (microseconds per second) a group should have CPU access.- Group wide upper limit on CPU time per second.- Weighted proportional value of relative CPU time for a group.
cpuset - CPUs (cores) the group can access.- Memory nodes the group can access and migrate ability.- Memory hardwall, pressure, spread, etc.
devices - Define which devices and access type a group can use.
freezer - Suspend/resume group tasks.
memory - Max memory limits for the group (in bytes).- Memory swappiness, OOM control, hierarchy, etc..
hugetlb - Limit HugeTLB size usage.
- Per cgroup HugeTLB metrics.
net_cls - Tag network packets with a class ID.
- Use tc to prioritize tagged packets.
net_prio - Weighted proportional priority on egress traffic (per interface).
LXC – Colocando para Funcionar
• Como fazer um server funcionar?
– Instalar os pacotes
– Config (rede / fs / memória / processador )
– RootFS ( images )
– LXC Tools
LXC – Pacotes
• RPM Based (Centos/RedHat etc)
– yum install libvirt libvirt-client python-virtinst
• Deb Based (Debian / Ubuntu / etc)
– sudo apt-get install lxc
• Enable cgroups
– none /cgroup cgroup defaults 0 0
LXC – Config
• Configurações dos recursos utilizados pelo
container
– Rede
– Rootfs
– Limitações
– Mount binds
– Segurança
LXC – Cgroups pseudofs
LXC – Config
• lxc.tty = 1
• lxc.utsname = b:u:inthosp:1
• lxc.pivotdir = mnt
• lxc.rootfs = /opt/phoenix/var/slot/b-u-inthosp-1/rootfs
• lxc.cgroup.cpu.shares = 1024
• lxc.cgroup.cpu.cfs_period_us= 100000
• lxc.cgroup.cpu.cfs_quota_us= 100000
• lxc.cgroup.memory.limit_in_bytes = 256M
• lxc.cgroup.memory.memsw.limit_in_bytes = 256M
• lxc.mount.entry = proc procproc nosuid,nodev,noexec 0 0
• lxc.network.0.type = veth
• lxc.network.0.flags = up
• lxc.network.0.link = br0
• lxc.network.0.name = eth1
• lxc.network.0.mtu = 1500
• lxc.network.0.ipv4 = 10.1.0.41/16
• lxc.network.0.veth.pair = veth40
• lxc.cgroup.devices.deny = a
LXC – Images
• Sua “ISO“
• Read-only para o container
• Shared
• Como gerar � Dockerdclient = docker.Client(base_url=docker_url,version='1.16',timeout=120)
container = dclient.create_container(base, "/usr/bin/python -u
/mnt/build/docker-template-setup.py", volumes=["/mnt/build",
"/var/cache/yum"], name="build-%s" % pkg)
...
resp = dclient.export(container)
tar = subprocess.Popen(["/bin/tar", "-x", "-C", imagedir],
stdin=subprocess.PIPE)
...
.SPEC para gerar o RPM
LXC – Images
LXC – Tools
• lxc-create -n shimoo-c -t debian
• lxc-start –n shimmo-c
• lxc-attach –n shimmo-c
LXC – Dicas
• Abstrair
• Kernel updates !!
– Vários erros no OOM durante o processo
• Kernel Debug
– Tenha seu kernel em debug mode em prod
– Kdump habilitado até ter certeza
• Testing...testing...more testing
• Overcommit ... A lot
• IT WORKS!!!
LXC Commoditization: docker
• Desacoplamento
• Agnóstico
• Imagens rodam em qualquer plataformasuportada pelo Docker
• Portabilidade
• Larga Adoção – muito fácil
• Sharing
• Integrações
Docker vs. LXC vs. Hypervisor
GO
• New
• https://golang.org/
• Funny
GO
• Camada de WS de alto nível para provisionar seu container:
• curl -si \
-H "Host: shimoo.com.br" \
-H "X-User: shimoo" \
-H "X-User-Domains: shimoo.com.br" \
-H "X-Homedir: ha-pool02/ha-pool02-fs02/shimoo/home" \
-H "X-Application: tomcat8;jdk=8" \
-H "X-Instance: 1" \
-H "X-Memory-Limit: 256" \
-H "X-CPU-Limit: 25" \
-H "X-Idle-Timout: 5" \
-H "X-Backend: b:u:shimoo:1" \
-H "X-Realhost: shimoo.com.br" \
http://localhost
Perguntas
Marcus Vinícius [email protected]