Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LXC & Test-Kitchen Tutorial

LXC & Test-Kitchen Tutorial

Bryan Berry

April 24, 2013
Tweet

More Decks by Bryan Berry

Other Decks in Technology

Transcript

  1. 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
  2. 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.*
  3. 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
  4. 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
  5. 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
  6. 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/*
  7. 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
  8. Bring in the clones $ sudo lxc-clone -o ubuntu -n

    foobar $ sudo lxc-start –n foobar $ ifconfig eth0
  9. awesome-ephemeral # console 1 $ sudo lxc-awesome-ephemeral -o ubuntu #

    that's faster # console 2 $ sudo lxc-console attach foo..
  10. 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
  11. 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
  12. 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
  13. 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
  14. .kitchen.yml • driver – currently AWS, LXC, vagrant, bluebox •

    platform – operating system or node in a cluster • suite – run list & set of attributes
  15. Why YAML? • easy to read • easy to parse

    • super flexible • great support for serializing data types
  16. 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 . . .
  17. 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
  18. My First .kitchen.yml $ bundle exec kitchen list $ bundle

    exec kitchen create default-ubuntu $ bundle exec kitchen destroy default-ubuntu
  19. 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