use Docker as OpenStack Cloud Operating System Compute Node - Nova's Hypervisor

简介:
OpenStack现已支持Docker作为Nova的Hypervisor, 同时支持将image存储在Glance中, 目前的版本还需要使用docker-registry来代理请求到glance获取image.
未来可能会去掉registry, 直接从glance获取image.

use Docker as OpenStack Cloud Operating System Compute Node - Novas Hypervisor - 德哥@Digoal - PostgreSQL research

部署步骤 : 
1. Nova节点安装Docker server, 赋予nova用户docker组权限.
2. 安装nova docker驱动
3. 在nova配置中, 改为默认使用docker driver
4. compute_driver = novadocker.virt.docker.DockerDriver
5. 让nova控制网络, 即使有netns, --net=none启动容器.
6. Glance配置, 添加docker镜像支持.
使用 : 
1. 下载docker镜像
2. 将docker镜像导入glance(例子)
docker pull samalba/hipache
docker save samalba/hipache | glance image-create --is-public=True --container-format=docker --disk-format=raw --name samalba/hipache
3. 使用nova启动容器(没有看到镜像下载过程, 已经在本地了, 如果镜像不在本地, 还需要配置registry, glance, 此处略)
nova boot --image "samalba/hipache" --flavor m1.tiny test

Configure OpenStack to enable Docker

Installing Docker for OpenStack

The first requirement is to install Docker on your compute hosts.

In order for Nova to communicate with Docker over its local socket, add nova to the docker group and restart the compute service to pick up the change:

usermod -G docker nova
service openstack-nova-compute restart

You will also need to install the driver:
pip install -e git+https://github.com/stackforge/nova-docker#egg=novadocker

You should then install the required modules
cd src/novadocker/
python setup.py install

You may optionally choose to create operating-system packages for this, or use another appropriate installation method for your deployment.

Nova configuration

Nova needs to be configured to use the Docker virt driver.

Edit the configuration file /etc/nova/nova.conf according to the following options:


[DEFAULT]
compute_driver = novadocker.virt.docker.DockerDriver

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

Glance configuration

Glance needs to be configured to support the "docker" container format. It's important to leave the default ones in order to not break an existing glance install.


[DEFAULT]
container_formats = ami,ari,aki,bare,ovf,docker

Deployment with DevStack

Using Docker hypervisor through DevStack replaces all manual configuration needed above.

Before running DevStack's stack.sh script, configure the following options in the "localrc" file:


VIRT_DRIVER=docker

Then, run follow instructions in the README.rst

Finally, run stack.sh from devstack directory:


$ ./stack.sh

How to use it

Once you configured Nova to use the docker driver, the flow is the same as any other driver.


$ glance image-list
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+
| ID                            | Name                            | Disk Format | Container Format | Size     | Status |
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+
| f5049d8b-93cf-49ab-af56-e7... | cirros-0.3.1-x86_64-uec         | ami         | ami              | 25165824 | active |
| 0f1ec86c-157f-4f22-9889-c0... | cirros-0.3.1-x86_64-uec-kernel  | aki         | aki              | 4955792  | active |
| 03a54807-2e35-4864-a337-45... | cirros-0.3.1-x86_64-uec-ramdisk | ari         | ari              | 3714968  | active |
| 77083f3c-d320-46e3-bcba-0c... | docker-busybox:latest           | raw         | docker           | 2271596  | active |
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+

Only images with a "docker" container format will be bootable. The image contains basically a tarball of the container filesystem.

It's recommended to add new images to Glance by using Docker. For instance, here is how you can fetch images from the public registry and push them back to Glance in order to boot a Nova instance with it:


 $ docker search hipache
Found 3 results matching your query ("hipache")
NAME                             DESCRIPTION
samalba/hipache                  https://github.com/dotcloud/hipache

Then, pull the image and push it to Glance:
 $ docker pull samalba/hipache
 $ docker save samalba/hipache | glance image-create --is-public=True --container-format=docker --disk-format=raw --name samalba/hipache

NOTE: The name you provide to glance must match the name by which the image is known to docker.
 $ glance image-list
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+
| ID                            | Name                            | Disk Format | Container Format | Size     | Status |
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+
| f5049d8b-93cf-49ab-af56-e7... | cirros-0.3.1-x86_64-uec         | ami         | ami              | 25165824 | active |
| 0f1ec86c-157f-4f22-9889-c0... | cirros-0.3.1-x86_64-uec-kernel  | aki         | aki              | 4955792  | active |
| 03a54807-2e35-4864-a337-45... | cirros-0.3.1-x86_64-uec-ramdisk | ari         | ari              | 3714968  | active |
| 77083f3c-d320-46e3-bcba-0c... | docker-busybox:latest           | raw         | docker           | 2271596  | active |
| 998f52ba-fe03-46b0-b5a6-4b... | samalba/hipache               | raw         | docker           | 486      | active |
+-------------------------------+---------------------------------+-------------+------------------+----------+--------+

You can obviously boot instances from nova cli:
 $ nova boot --image "samalba/hipache" --flavor m1.tiny test
+--------------------------------------+--------------------------------------+
| Property                             | Value                                |
+--------------------------------------+--------------------------------------+
| OS-EXT-STS:task_state                | scheduling                           |
| image                                | samalba/hipache                |
| OS-EXT-STS:vm_state                  | building                             |
| OS-EXT-SRV-ATTR:instance_name        | instance-0000002d                    |
| OS-SRV-USG:launched_at               | None                                 |
| flavor                               | m1.micro                             |
| id                                   | 31086c50-f937-4f80-9790-045096ecb32c |
| security_groups                      | [{u'name': u'default'}]              |
| user_id                              | 1a3eed38d1344e869dd019b3636db12b     |
| OS-DCF:diskConfig                    | MANUAL                               |
| accessIPv4                           |                                      |
| accessIPv6                           |                                      |
| progress                             | 0                                    |
| OS-EXT-STS:power_state               | 0                                    |
| OS-EXT-AZ:availability_zone          | nova                                 |
| config_drive                         |                                      |
| status                               | BUILD                                |
| updated                              | 2013-08-25T00:22:32Z                 |
| hostId                               |                                      |
| OS-EXT-SRV-ATTR:host                 | None                                 |
| OS-SRV-USG:terminated_at             | None                                 |
| key_name                             | None                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | None                                 |
| name                                 | test                                 |
| adminPass                            | QwczSPAAT6Mm                         |
| tenant_id                            | 183a9b7ed7c6465f97387458d693ca4c     |
| created                              | 2013-08-25T00:22:31Z                 |
| os-extended-volumes:volumes_attached | []                                   |
| metadata                             | {}                                   |
+--------------------------------------+--------------------------------------+

Once the instance is booted:
$ nova list
+--------------------------------------+------+--------+------------+-------------+------------------+
| ID                                   | Name | Status | Task State | Power State | Networks         |
+--------------------------------------+------+--------+------------+-------------+------------------+
| 31086c50-f937-4f80-9790-045096ecb32c | test | ACTIVE | None       | Running     | private=10.0.0.2 |
+--------------------------------------+------+--------+------------+-------------+------------------+

You can also see the corresponding container on docker:
$ docker ps
docker ps
ID              IMAGE                                  COMMAND      CREATED             STATUS          PORTS
f337c7fec5ff    samalba/hipache              sh           10 seconds ago      Up 10 seconds

The command used here is the one configured in the image. Each container image can have a command configured for the run. The driver does not usually override this. You can image booting an apache2 instance, it will start the apache process if the image is authored properly via a Dockerfile.

Resources

Nickoloff, Jeff; Docker in Action, Manning Publications, 2014, ISBN 978-1-6334-3023-5


[参考]
相关文章
|
1月前
|
JavaScript Docker 容器
利用docker部署Node-RED
利用docker部署Node-RED
78 1
|
2月前
|
JavaScript NoSQL Redis
深入浅出:使用 Docker 容器化部署 Node.js 应用
在当今快速发展的软件开发领域,Docker 作为一种开源的容器化技术,已经成为了提高应用部署效率、实现环境一致性和便于维护的关键工具。本文将通过一个简单的 Node.js 应用示例,引导读者从零开始学习如何使用 Docker 容器化技术来部署应用。我们不仅会介绍 Docker 的基本概念和操作,还会探讨如何构建高效的 Docker 镜像,并通过 Docker Compose 管理多容器应用。此外,文章还将涉及到一些最佳实践,帮助读者更好地理解和应用 Docker 在日常开发和部署中的强大功能。
66 0
|
2月前
|
运维 JavaScript 开发者
深入浅出:使用Docker容器化部署Node.js应用
在当今快速发展的软件开发领域,构建一套高效、可靠且易于扩展的开发环境成为了许多开发者和企业的首要任务。本文将探讨如何利用Docker这一强大的容器化技术,实现对Node.js应用的快速部署和管理。不同于传统的摘要方式,我们将通过一个实际操作的视角,逐步引导读者理解Docker的基本概念、容器与镜像的区别、以及如何构建自己的Node.js应用Docker镜像,最终实现应用的容器化部署。此外,文章还将简要介绍Docker Compose的使用,帮助读者管理包含多个服务的复杂应用。无论是刚接触Docker的新手,还是希望深化理解容器化技术的资深开发者,本文都将提供有价值的见解。
37 0
|
4月前
|
资源调度 前端开发 Shell
使用 Docker Node 镜像运行项目
使用 Docker Node 镜像运行项目
|
6月前
|
安全 jenkins 持续交付
企业实战(23)基于Docker平台的Jenkins添加node节点与报错详解(2)
企业实战(23)基于Docker平台的Jenkins添加node节点与报错详解(2)
|
7月前
|
监控 开发工具 Docker
Docker 镜像构建:Python & Node
Docker 镜像构建:Python & Node
319 0
|
9月前
|
JavaScript 开发工具 C语言
Docker发布node-hexo镜像
使用 Dockerfile 基于 alpine 系统,构建 nodejs 环境和 hexo 基础依赖以及 git 环境。
169 0
Docker发布node-hexo镜像
|
JavaScript Linux 应用服务中间件
Docker部署Node应用简单实践
本文将从零至一,介绍如何在云服务器上通过 Docker 容器运行一个简单的Node应用。
1218 0
|
JavaScript Linux C++
Docker构建Node.js应用镜像
Docker构建Node.js应用镜像
392 0
|
NoSQL 安全 程序员
Docker 部署Node服务
以前部署项目时候总会遇到本地环境和线上环境不一致产生排查困难的问题。在使用window系统的电脑开发学习时,但想要学习linux系统的一些操作或者项目的部署时,还需要一台服务器或者一个虚拟机,而Docker不仅部署方便而且更安全,Docker容器是个比较轻量的,占用资源少,成本低等等众多优势。所以,Docker 势必是程序员必会的一个工具之一。
530 0