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. LXC + Test-Kitchen Tutorial
    chefconf 2013, Bryan W. Berry

    View Slide

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

    View Slide

  3. 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

    View Slide

  4. 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.*

    View Slide

  5. 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

    View Slide

  6. 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

    View Slide

  7. 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

    View Slide

  8. 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/*

    View Slide

  9. 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  13. 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

    View Slide

  14. 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

    View Slide

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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

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

    View Slide

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

    View Slide

  20. 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 . . .

    View Slide

  21. 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

    View Slide

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

    View Slide

  23. 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

    View Slide