Thursday, February 23, 2012

Easy creating and destroying of lxc vservers

One big advantage of using amazon's EC2 servce is its deceptively easy way to create new servers - it is just API call or mouseclick away. The actual physical machine allocation, OS image copying, hostname, IP, dns, firewall and routing setup are done transparently in the background. You are only required to setup the payment ;) .

Big enterprise virtualization technology providers already have a mechanism to create virtual machines with given parameters on demand. Such a system would likely be overkill for a handful of physical servers. I also doubt they support the highly effective pseudo-virtualization LXC technology.

Thus I created a python "lmachine" script for our LXC servers, that copies an OS image into a selected "slot" with already pre-allocated IP number and server name. The script also modifies a couple of system files from the OS image accordingly.

The script can be downloaded here.

Preparing an LXC image

LXC images are easily created using the debootstrap utility. To make them ready for the lmachine script, you need to set the actual IP number with the IPNUMBER string and the actual server name with the VSERVERNAME string. Here is the list of files that needs to be modified:
  • fstab
  • lxc.conf
  • root/etc/network/interfaces
  • root/etc/hosts
  • root/etc/hostname
  • root/etc/mailname
Make sure you pre-allocate IP numbers and ltestXX DNS domain names in advance. Update the lmachine script with the list of pre-allocated IP numbers.

6 comments:

Anonymous said...

What are your thoughts on:
http://www.activestate.com/blog/2011/10/virtualization-ec2-cloud-using-lxc

Arie Skliarouk said...

Running LXC from inside of EC2's XEN? Hmm...

While it is entirely possible, I can not imagine that being useful to anyone. Without controlling IP numbers allocation (even in the private address space), you are painted into corner of using loopback-bound IP numbers (127.*) only.

Ohad Levy said...

Nice Article, If you want to get IP address auto management, you could reuse https://github.com/theforeman/smart-proxy

If you are interested, I would be happy to try and see if we can integrate it into foreman (http://theforeman.org)

Arie Skliarouk said...

You are welcome to take the script and integrate it into the foreman system.

You can even borrow my LLS scripts to allocate space for the vservers dynamically.

virtualization technology said...

Currently I work for Dell and thought your blog on Linux zealot is really informative. The information about IP address in very useful. Thanks for sharing with us.

bmullan said...

Running LXC in AWS's EC2 is very useful in several ways.
One I just tried the other day was to deploy OpenStack in EC2 using LXC containers... it worked!
Also, deploying container bound servers that are all in their own DNS/DHCP network can be very useful on EC2.