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



[参考]
目录
相关文章
|
21天前
|
缓存 JavaScript 持续交付
“解锁Node.js新纪元:如何借助Docker打造快速、高效且一致性的现代应用部署体验”
【10月更文挑战第25天】本文介绍了如何使用Docker容器化Node.js应用,包括容器化的好处、创建Docker镜像的步骤、构建和运行镜像的方法、管理依赖、保持应用更新以及调试技巧。通过容器化,可以提高应用的可移植性和可扩展性,简化开发和部署流程。
24 2
|
3月前
|
存储 API 调度
OpenStack的计算服务(Nova)
【8月更文挑战第23天】
235 9
|
3月前
|
API 调度 数据库
OpenStack核心组件Nova
【8月更文挑战第4天】
112 9
|
6月前
|
Linux 网络安全 API
云计算|OpenStack|社区版OpenStack安装部署文档(五 --- 计算服务nova安装部署---Rocky版)
云计算|OpenStack|社区版OpenStack安装部署文档(五 --- 计算服务nova安装部署---Rocky版)
357 0
|
6月前
|
应用服务中间件 nginx Docker
Docker中报错 Error response from daemon: Conflict. The container name “/nginx01“ is already in use
在尝试运行 `docker run -d --name nginx01 -p 3344:80 nginx` 时遇到错误。问题源于已有名为 nginx01 的容器未正确终止,造成命名冲突。解决方法:首先使用 `docker ps -a` 查看所有容器,然后删除现有 nginx01 容器,执行 `docker rm <container_id>`(替换 `<container_id>` 为实际容器ID),最后再运行 `docker run` 命令即可。
311 0
|
6月前
|
JavaScript Docker 容器
利用docker部署Node-RED
利用docker部署Node-RED
400 1
|
6月前
|
JavaScript NoSQL Redis
深入浅出:使用 Docker 容器化部署 Node.js 应用
在当今快速发展的软件开发领域,Docker 作为一种开源的容器化技术,已经成为了提高应用部署效率、实现环境一致性和便于维护的关键工具。本文将通过一个简单的 Node.js 应用示例,引导读者从零开始学习如何使用 Docker 容器化技术来部署应用。我们不仅会介绍 Docker 的基本概念和操作,还会探讨如何构建高效的 Docker 镜像,并通过 Docker Compose 管理多容器应用。此外,文章还将涉及到一些最佳实践,帮助读者更好地理解和应用 Docker 在日常开发和部署中的强大功能。
1312 0
|
6月前
|
运维 JavaScript 开发者
深入浅出:使用Docker容器化部署Node.js应用
在当今快速发展的软件开发领域,构建一套高效、可靠且易于扩展的开发环境成为了许多开发者和企业的首要任务。本文将探讨如何利用Docker这一强大的容器化技术,实现对Node.js应用的快速部署和管理。不同于传统的摘要方式,我们将通过一个实际操作的视角,逐步引导读者理解Docker的基本概念、容器与镜像的区别、以及如何构建自己的Node.js应用Docker镜像,最终实现应用的容器化部署。此外,文章还将简要介绍Docker Compose的使用,帮助读者管理包含多个服务的复杂应用。无论是刚接触Docker的新手,还是希望深化理解容器化技术的资深开发者,本文都将提供有价值的见解。
110 0
|
JavaScript Linux 应用服务中间件
Docker部署Node应用简单实践
本文将从零至一,介绍如何在云服务器上通过 Docker 容器运行一个简单的Node应用。
2062 0
|
6月前
|
资源调度 前端开发 Shell
使用 Docker Node 镜像运行项目
使用 Docker Node 镜像运行项目
472 0