设为首页 收藏本站
查看: 1221|回复: 0

[经验分享] Openstack容器项目之Magnum

[复制链接]

尚未签到

发表于 2017-6-26 11:07:20 | 显示全部楼层 |阅读模式
本文以Newton版本为例。  1.Magnum简介
Magnum项目通过Openstack API能够在Openstack中创建基于容器的服务,但它本身并不直接对容器进行操作,而是通过Kubernetes, Swarm或者Mesos后端进行管理。Openstack正式项目Zun具有直接管理docker的功能。
Magnum特征:
(1)Clusters(node对象的集合, 以前版本称为Bay)抽象化。
(2)与Kubernetes, Swarm以及Mesos进行集成,管理容器。
(3)与Keystone集成,提供多租户安全。
(4)与Neutron集成,为Kubernetes提供多租户安全。
(5)与Cinder集成,为容器提供volume服务。

2.Magnum架构
DSC0000.png
说明:
Bay: 与Cluster意思相同,代表一组node的集合。
Node: 容器运行的节点,可以是裸机、虚拟机或者容器本身。
Pod: 运行在同一个Node上一组容器集合, 来源于kubernetes。
Service: 由一个或者多个 Pod 组成,代表一个抽象的应用服务,对外呈现为同一个访问接口,这样访问可以通过 service 来路由,而无需具体知道 Pods 的地址。
Baymodel: 用来存储Bay的模板的对象,类似于Nova中的flavor。
RC:ReplicationController,对 pod 指定副本数,可以保证一直存在该数目的副本存在并运行。

工作流程举例:用户通过GUI(Magnum UI)或者Magnum命令行client端,输入cluster update请求,magnum-api 进程接收到消息进行解析,将消息通过RPC消息队列转发到进程magnum-conductor进行下一步处理,magnum-conductor根据cluster的属性选择后端driver进行处理,如kubernetes, 最后通过heat组件使用template来进行执行具体的update操作。   3.Magnum命令
commandparametersfunctionexample
cluster-create  --cluster-template \ The ID or name of the ClusterTemplate to use.
  --name \ Name of the cluster to create.
  --keypair \ The name or UUID of the SSH keypair to configure in the cluster servers for ssh access.
  --node-count \ The number of servers that will serve as node in the cluster.
  --master-count \ The number of servers that will serve as master for the cluster.
  --discovery-url \ The custom discovery url for node discovery.
  --timeout \ The timeout for cluster creation in minutes.
创建一个cluster,以异步的方式执行。  magnum cluster-create --name mycluster \
  --cluster-template mytemplate \
  --node-count 8 \
  --master-count 3
  说明:使用名为mytemplate的模板, 创建了一个拥有8个node, 3个master node, 名为mycluster的cluster
cluster-delete 通过name或ID删除一个clustermagnum cluster-delete mycluster
cluster-list 列出所以得clustermagnum cluster-list
cluster-show 显示某个cluster的详细信息magnum cluster-show mycluster
cluster-update  <cluster> \ This is the first parameter, specifying the UUID or name of the cluster to update.
  <op> \ This is the second parameter, specifying the desired change to be made to the cluster attributes. The allowed changes are 'add', 'replace' and 'remove'.
  <attribute=value> \ This is the third parameter, specifying the targeted attributes in the cluster as a list separated by blank space.
更新某个cluster  magnum cluster-update mycluster replace node_count=8
  说明:把mycluster中的node节点设置为8
cluster-template-create  --coe \ Specify the Container Orchestration Engine to use. Supported COE's include 'kubernetes', 'swarm', 'mesos'.
  --image \ The name or UUID of the base image in Glance to boot the servers for the cluster.
  --keypair \ The name or UUID of the SSH keypair to configure in the cluster servers for ssh access.
  --external-network \ The name or network ID of a Neutron network to provide connectivity to the external internet for the cluster.
  --name \ Name of the ClusterTemplate to create.
  --public \ Access to a ClusterTemplate is normally limited to the admin, owner or users within the same tenant as the owners.
  --server-type \ The servers in the cluster can be VM or baremetal.
  --volume-driver \ The name of a volume driver for managing the persistent storage for the containers.
  --dns-nameserver \ The DNS nameserver for the servers and containers in the cluster to use.
  --flavor \ The nova flavor id for booting the node servers.
  --master-flavor \ The nova flavor id for booting the master or manager servers.
  --http-proxy /--https-proxy \ The IP address for a proxy to use when direct http/https access from the servers to sites on the external internet is blocked.
  --no-proxy \ When a proxy server is used, some sites should not go through the proxy and should be accessed normally.
  --docker-volume-size \ If specified, container images will be stored in a cinder volume of the specified size in GB.
  --docker-storage-driver \ The name of a driver to manage the storage for the images and the container's writable layer.
  --labels \ Arbitrary labels in the form of key=value pairs.
  --tls-disabled \ Transport Layer Security (TLS) is normally enabled to secure the cluster.
  --registry-enabled \ Docker images by default are pulled from the public Docker registry, but in some cases, users may want to use a private registry.
  --master-lb-enabled \ Since multiple masters may exist in a bay, a load balancer is created to provide the API endpoint for the bay and to direct requests to the masters.
创建cluster template  magnum cluster-template-create --name mesos-cluster-template \
  --image ubuntu-mesos \
  --keypair testkey \
  --external-network public \
  --dns-nameserver 8.8.8.8 \
  --master-flavor m1.magnum \
  --docker-volume-size 4 \
  --tls-disabled \
  --flavor m1.magnum \
  --coe mesos \
  --volume-driver rexray \
  --labels rexray-preempt=true
cluster-template-delete 删除某个模板magnum cluster-template-delete mytemplate
cluster-template-list 列出所有的模板magnum cluster-template-delete
cluster-template-show 显示某个模板的详细信息magnum cluster-template-show mytemplate
cluster-template-update 更新某个模板magnum cluster-template-update mytemplate [ ...]
service-list 列出所以得magnum servicemagnum service-list
ca-show 显示某个cluster CA certificate 的详细信息magnum ca-show mycluster
ca-sign  --csr File path of the csr file to send to Magnum to get signed.
  --cluster ID or name of the cluster.
为某个cluster产生一个CA certificate
cluster-config Configure native client to access cluster.
stats-list Show stats for the given project_idmagnum stats-list [--project-id ]
  说明:
(1)当前版本中支持的image如下。
COEos-distro
KubernetesFedora-atomic, CoreOS
SwarmFedora-atomic
MesosUbuntu
  (2)当前版本支持的容器network-driver如下。
COENetwork-DriverDefault
KubernetesFlannelFlannel
SwarmDocker, FlannelFlannel
MesosDockerDocker
  (3)当前版本支持的容器volume-driver如下。
COEVolume-DriverDefault
KubernetesCinderNo Driver
SwarmRexrayNo Driver
MesosRexrayNo Driver
  4.Magnum源码结构
DSC0001.png
说明:
api:以Pecan框架(http://www.pecanpy.org/)基础的API请求处理代码,接收到客户端请求后,进行解析转发或者直接处理。
cmd: 整个Magnum组件对外提供操作的入口。
common: 公共代码。
condutor: magnum-conductor接收到magnum-api消息后,在此处选择相应的driver进行下一步处理。
conf: 配置相关代码。
db: sqlalchemy相关代码,包括数据库migrating功能。
drviers: 后端各种driver(Kubernetes, Swarm以及Mesos)相关代码。
hacking: 供magnum单元测试使用的检测对象。
objects: 数据库model抽象,提供操作数据库功能。
service:周期性更新clusters状态至数据库。
servicegroup: 周期性更新magnum服务组状态至数据库。
tests: 单元测试相关代码。
  5.Magnum代码流程分析
(1)启动脚本
安装完Magnum组件,会在系统/usr/bin目录下面生产4个可执行脚本,与源码文件setup.cfg中设置相对应,如下图所示。系统默认启动magnum-api和magnum-conductor脚本,magnum系统即可正常工作,magnum-db-manage和magnum-driver-manage可用于手动操作,完成相关任务。 DSC0002.png
magnum-api: 负责接收处理以及转发client的请求消息。
magnum-conductor: 负责接收magnum-api所发出的消息,进行cluster等具体操作。
magnum-db-manage: 负责数据库的stamp,upgrade,version相关操作。
magnum-driver-manage: 负责管理后端各种driver(Kubernetes, Swarm以及Mesos)相关配置。
(2)代码流程
DSC0003.png
如上图所示,Magnum逻辑功能主要三个方面.
(1)通过magnum-db-manage控制数据库的migrating,目前只支持sqlalchemy的backend, 位于源码文件setup.py, 如下图所示。
DSC0004.png
执行过程:调用源码文件magnum/cmd/db_manage.py:main, 之后调用magnum/db/migration.py直接操作,如下图所示。此过程较简单,不再深入。
DSC0005.png
(2)通过magnum-driver-manage脚本,调用源码文件magnum/cmd/driver_manage.py:main,之后调用magnum/drivers/driver.py, 管理drivers/目录下各种driver(Kubernetes, Swarm以及Mesos)的相关配置。此过程较简单,不再深入。
DSC0006.png
(3)magnum-api消息处理流程:通过magnum-api脚本,调用源码文件magnum/cmd/api.py,之后系统进入api目录完成消息的解析以及处理。整个api目录下的代码以Pecan为框架组成,如下图所示。

DSC0007.jpg

  说明:
(1)magnum-api接收到消息后,经Middleware进行过滤。
(2)之后由Pecan Route转发消息至相应的分支进行处理。
(3)Cluster和Certificate分支相关的消息,被发送到消息队列服务端,由magnum-conductor进程处理。其它分支消息只需跟数据库进行交互。

  magnum-conductor消息处理大致流程:此进程启动RPC service接受magnum-api发出的消息,之后转发到相应的endpoint进行处理,如下图所示,位于源码文件cmd/conductor.py。
DSC0008.png
之后跳转到与endpoint对应的conductor/handlers/目录下进行处理,如下图所示。
DSC0009.png
其中,ca_conductor.py:具体负责certificate相关消息处理,包括生成,存储,删除以及读取certificate操作。支持不同的backend来进行相关的certificate操作,位于源码文件setup.py, 如下图所示。
DSC00010.png
cluster_conductor.py:负责处理cluster create,update,delete操作,根据cluster的属性选择相应的后端driver(kuberntes, mesos或者swarm, 位于源码文件setup.py, 如下图所示),最后通过heat组件以template形式来执行cluster相关的操作。
DSC00011.png
conductor_listener.py:代表magnum-conductor alive状态,即相当于keepalive概念。
indirection_api.py:主要用于处理与数据库相关操作。

  参考文章:
1.http://docs.openstack.org/developer/magnum/
2.https://wiki.openstack.org/wiki/Magnum
3.https://github.com/openstack/magnum

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-388167-1-1.html 上篇帖子: OpenStack Mitaka 版本中的 domain 和 admin 下篇帖子: 在 ML2 中配置 OVS flat network
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表