Slide 1

Slide 1 text

LXC + Test-Kitchen Tutorial chefconf 2013, Bryan W. Berry

Slide 2

Slide 2 text

Overview • The Setup • Demo • LXC Concepts • Test-Kitchen Concepts • Hack!

Slide 3

Slide 3 text

The Setup • Ubuntu 12.04 or 12.10 with 2 partitions, 1 smaller one unpartitioned $ sudo apt-get install -y lxc ruby1.9 ruby1.9-dev $ sudo gem install bundler chef -–no-ri –-no-rdoc $ sudo gem install test-kitchen -–pre –-no-rdoc $ git clone git://github.com/bryanwb/vagabond.git $ cd vagabond && git checkout new-lxc-cookbook $ sudo ln -s vagabond/lib/cookbooks/lxc/files/default/lxc-awesome-ephermal / usr/bin/lxc-awesome-ephemeral

Slide 4

Slide 4 text

Vagabond • created by Chris Roberts • helps you get started with lxc and test-kitchen • has a number of awesome features • Totally alpha • Only works on ubuntu 12.*

Slide 5

Slide 5 text

Demo • Let's create a 3-node cassandra cluster $ bundle exec kitchen create all –p .... $ bundle exec kitchen converge all –p .... $ bundle exec kitchen destroy all -p

Slide 6

Slide 6 text

LXC is . . . a collection of tools to create an isolated environment Not really virtualization, just feels like it It's a container, not a VM

Slide 7

Slide 7 text

LXC Concepts • All containers share the same kernel • We use cgroups to "namespace" or isolate resources per container • containers can sometimes see aspects of each other or the host

Slide 8

Slide 8 text

Stuff • Default config file in /etc/lxc/lxc.conf • Templates in /usr/share/lxc/templates • Actual containers stored in /var/lib/lxc • lxcbr0 used to connect containers to the world • dnsmasq – lightweight dns and dhcp server /var/lib/misc/dnsmasq.leases • run-time info in /sys/fs/cgroup/container_name/*

Slide 9

Slide 9 text

Create a Base Container $ sudo lxc-create –t ubuntu –n foobar $ sudo lxc-start –n foobar foobar exists at /var/lib/lxc/foobar/ all the container-settings in /var/lib/lxc/foobar/config rootfs in /var/lib/lxc/foobar/rootfs

Slide 10

Slide 10 text

Bring in the clones $ sudo lxc-clone -o ubuntu -n foobar $ sudo lxc-start –n foobar $ ifconfig eth0

Slide 11

Slide 11 text

awesome-ephemeral # console 1 $ sudo lxc-awesome-ephemeral -o ubuntu # that's faster # console 2 $ sudo lxc-console attach foo..

Slide 12

Slide 12 text

Let's go faster! $ sudo lxc-awesome-ephemeral -o ubuntu –I 10.0.3.100

Slide 13

Slide 13 text

We've been cheating • lxc-awesome-ephemeral is just lxc-clone but stores container image in tmpfs by default • limits all your vms to the size of available RAM

Slide 14

Slide 14 text

Modern Filesystems to the Rescue • We can use LVM, BTRFS, or even a Virtual Block Device (VBD) to run just as fast • Time to use that second partition $ sudo apt-get install –y btrfs-tools $ sudo parted /dev/sdx $ sudo mkfs.btrfs /dev/sdx1 $ sudo mount /dev/sdx1 /var/lib/lxc

Slide 15

Slide 15 text

overlay $ sudo lxc-awesome-ephemeral -o ubuntu -z /usr/lib/lxc Now you're cooking with butter!

Slide 16

Slide 16 text

lxc-awesome-bastard-ephemeral $ sudo lxc-awesome-ephemeral -o ubuntu –n foobar –I 10.0.3.100 -d -z /usr/lib/lxc $ sudo lxc-awesome-ephemeral –cleanup -o ubuntu –n foobar –I 10.0.3.100 -d -z /usr/lib/lxc

Slide 17

Slide 17 text

Test-Kitchen 1.0 Concepts • Test a cookbook against multiple distros/OS • Create and converge multiple distro/recipe combinations in parallel • Be easy to script • support different backends (drivers) • create & spin up clusters of nodes in parallel* *Proposed addition by Chris Robert

Slide 18

Slide 18 text

.kitchen.yml • driver – currently AWS, LXC, vagrant, bluebox • platform – operating system or node in a cluster • suite – run list & set of attributes

Slide 19

Slide 19 text

Why YAML? • easy to read • easy to parse • super flexible • great support for serializing data types

Slide 20

Slide 20 text

Create a Gemfile Create a Gemfile gem'kitchen-lxc', git: 'git://github.com/bryanwb/kitchen-lxc.git', branch: 'awesome-ephemeral' gem 'berkshelf' gem 'kitchen', git: 'git://github.com/opscode/test-kitchen.git', branch: 1.0 $ bundle install From here on out, use $ bundle exec kitchen . . .

Slide 21

Slide 21 text

Berkshelf Test-Kitchen uses Berkshelf to resolve cookbook dependencies and copy them into containers We won't be manually invoking it though for this tutorial

Slide 22

Slide 22 text

My First .kitchen.yml $ bundle exec kitchen list $ bundle exec kitchen create default-ubuntu $ bundle exec kitchen destroy default-ubuntu

Slide 23

Slide 23 text

Ideas • Add test-kitchen support to one of your cookbooks • Create a centos container and converge it • Use docker instead of lxc-awesome-ephemeral • Figure out what AUFS and how to use it Chris Roberts will be in later for your consultation/harrassment