Share
Embed
LXC & Test-Kitchen Tutorial
Bryan Berry
April 24, 2013
Transcript
23 slides
-
Overview • The Setup • Demo • LXC Concepts •
Test-Kitchen Concepts • Hack! -
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 -
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.* -
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 -
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 -
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 -
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/* -
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 -
Bring in the clones $ sudo lxc-clone -o ubuntu -n
foobar $ sudo lxc-start –n foobar $ ifconfig eth0 -
awesome-ephemeral # console 1 $ sudo lxc-awesome-ephemeral -o ubuntu #
that's faster # console 2 $ sudo lxc-console attach foo.. -
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 -
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 -
overlay $ sudo lxc-awesome-ephemeral -o ubuntu -z /usr/lib/lxc Now you're
cooking with butter! -
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 -
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 -
.kitchen.yml • driver – currently AWS, LXC, vagrant, bluebox •
platform – operating system or node in a cluster • suite – run list & set of attributes -
Why YAML? • easy to read • easy to parse
• super flexible • great support for serializing data types -
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 . . . -
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 -
My First .kitchen.yml $ bundle exec kitchen list $ bundle
exec kitchen create default-ubuntu $ bundle exec kitchen destroy default-ubuntu -
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