Friday, February 26, 2016

Nova Docker Installation

After going through a lot of links (some good, some confusing), I finally figured out the installation of nova-docker. So whats the whole idea ?
When we create an OpenStack compute node with kvm as the underlying hypervisor, the VMs on that node get created using kvm hypervisor. Simple..
In the same way, there's a nova-docker driver. When we use nova-docker driver on a compute node, we can create docker containers using the "nova boot" command. That's what I did on my OpenStack kilo setup.

I created an All-in-one OpenStack kilo setup and used qemu as the hypervisor. Then, I thought of adding another compute node to the setup - but this one with nova-docker driver. Without any delay, I'll tell you how I did it (Though you would find a lot of links on it, but I prefer writing it my way :) ).

Step 1: Install docker on your VM - http://docs.docker.io/en/latest/installation/
Step 2: usermod -aG docker nova
Step 3: pip install docker-py
Step 4: git clone https://github.com/stackforge/nova-docker
[Steps 1-4 copied shamelessly from here]
Step 5: git checkout stable/kilo
Step 6: cd nova-docker
    Step 6.1: Edit the file driver.py - vi novadocker/virt/docker/driver.py as explained below
                   In def spawn(...), args{} needs to be edited as given below:

                    args = {
                   'hostname': instance['name'],
                   'mem_limit': self._get_memory_limit_bytes(instance),
                   'cpu_shares': self._get_cpu_shares(instance),
                   'network_disabled': True,
                   'tty': True,   # This line needs to be added.
        }
[Now again, step 6.1 is copied from here.]
Step 7: Follow the steps to configure and install a compute node from Openstack Kilo guide. - http://docs.openstack.org/kilo/install-guide/install/apt/content/neutron-compute-node.html
Step 8:python setup.py install - Install the nova-docker driver.
Step 9: Now we need to make some modifications to the nova configuration files that we edited in step 7. In "/etc/nova/nova.conf" under DEFAULT section, set 
compute_driver = novadocker.virt.docker.DockerDriver 
In /etc/nova/nova-compute.conf, we will set the compute driver as novadocker [that we installed in step 8].
cat /etc/nova/nova-compute.conf 
[DEFAULT]
#compute_driver=libvirt.LibvirtDriver
compute_driver=novadocker.virt.docker.DockerDriver
[libvirt]
virt_type=qemu
Step 10: Create the directory /etc/nova/rootwrap.d, if it does not already exist, and inside that directory create a file "docker.filters" with the following content:

# nova-rootwrap command filters for setting up network in the docker driver
# This file should be owned by (and only-writeable by) the root user

[Filters]
# nova/virt/docker/driver.py: 'ln', '-sf', '/var/run/netns/.*'
ln: CommandFilter, /bin/ln, root

Step 11: In "/etc/glance/glance-api.conf", set 
container_formats=ami,ari,aki,bare,ovf,ova,docker

Step 12: Follow "Uploading Images to Glance" onwards from this. If you get any error, follow this link. I got some of the same errors as described in this wonderful link. Many thanks to the author.

Once you are done with this, I would suggest you to create a new availability zone for this compute host. This way, while creating the docker instance, you can choose the docker availability zone. Here's what I did,

Step 1: nova aggregate-create docker-aggregate docker-availability-zone 
Step 2: nova aggregate-add-host

Now you can create an instance using the docker image. Check your instance using docker ps command on the compute node that we just created.

Thats all folks, I have consolidated everything in this blog post along with the helpful links. 

Putting all the links that I used for reference: