分享

OpenStack Heat 模板学习一 之hello world

52Pig 发表于 2014-10-8 22:53:56 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 58663
本帖最后由 pig2 于 2014-10-14 09:13 编辑
阅读导读:
1.什么是Heat?
2.学习Heat主要学习什么内容?
3.如何安装Heat?








Heat 类似于AWS的CloudFormation, 是OpenStack Orchestration进程的一个项目,OpenStack Orchestration旨在创建一个人性化的服务去管理整个云架构,服务和应用的生命周期。heat实现了一种自动化的通过简单定义和配置就能实现的云部署方式。可以在heat模板中定义连串相关任务(例如用某配置开几台虚拟机,然后再去在其中一台中安装一个mysql服务,设定相关数据库属性,然后再配置几台虚拟机安装web服务集群等等),然后交由heat,由heat按照一定的顺序执行heat模板中定义的一连串任务。利用heat还可以连接到neutron来帮助编排负载均衡和其他网络功能。
学习heat主要学习heat的template,heat的template描述了所用的所有组件资源以及组件资源之间的关系。 这些资源包括:servers,floating ips, volumes, security groups, users and others. Heat管理这些组件的生命周期,当你需要对现在的部署做一些修改的时候,你只需要对template做一些修改即可。Heat还可以与其他软件管理工具集成比如Puppet以及chef。


安装Heat
选择一个VM镜像,可以选择 http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2F20,它包含了heat-cfntools包,当运行./stack.sh的时候Heat将会被加载到screen中前缀是h-. 假如需要使用Ceilometer Alarms功能你需要添加Ceilometer功能。需要做的是在devstack的localrc文件中添加如下:

  1. CEILOMETER_BACKEND=mysql
  2. enable_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-api
  3. enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator
  4. #sudo apt-get install gitgit-review ctags
复制代码

首先下载devstack
#git clone https://github.com/openstack-dev/devstack.git
然后准备localrc如下,灵活选择你感兴趣的项目,做减法处理。注意假如你的环境在proxy后面,而proxy又不支持git时,可以将stackrc中的GIT_BASE=${GIT_BASE:-git://git.openstack.org}改为GIT_BASE=${GIT_BASE:-https://github.com}

  1. #The localrc is used to deploy a Neutron+OVS+heat+ceilometer+tempest development env  
  2. #OFFLINE True if no need to pull necessary packages again  
  3. #OFFLINE=True  
  4. #RECLONE True if all need a fresh repo environment  
  5. #RECLONE=True  
  6. ADMIN_PASSWORD=123  
  7. MYSQL_PASSWORD=123  
  8. RABBIT_PASSWORD=123  
  9. SERVICE_PASSWORD=123  
  10. SERVICE_TOKEN=123  
  11. Q_PLUGIN=openvswitch  
  12. disable_service n-net  
  13. #enable necessary network comps  
  14. ENABLED_SERVICES+=,neutron,q-svc,q-agt,q-dhcp,q-l3,q-meta  
  15. #enable advanced services  
  16. enable_service q-vpn q-lbaas q-fwaas  
  17. #enable tempest for learning tempest  
  18. enable_service tempest  
  19. #enable heat  
  20. enable_service heat h-api h-api-cfn h-api-cw h-eng  
  21. #enable ceilometer for Ceilometer Alarms  
  22. CEILOMETER_BACKEND=mysql  
  23. enable_service ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-anotification  
  24. enable_service ceilometer-api  
  25. enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator  
  26.    
  27. HOST_IP=<Host-IP>  
  28. #VM images  
  29. IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-i386-uec.tar.gz"  
  30. #IMAGE_URLS+=",http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img"  
  31. IMAGE_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2"  
  32.    
  33. http_proxy=<http-proxy>  
  34. https_proxy=<https-proxy>  
  35. no_proxy=localhost,<Host-IP>  
  36.    
  37. #for IPSec VPNaaS  
  38. IPSEC_PACKAGE=openswan  
  39.    
  40. #LOG configure  
  41. SCREEN_LOGDIR=/opt/stack/screen-logs  
  42. SYSLOG=True  
  43. #DEST=/opt/stack/project  
复制代码
一切准备就绪,最好先update&upgrade一下,然后运行./stack.sh 可以部署openstack环境了。
模板
https://github.com/openstack/heat-templates 提供一些templates参考例子来展示heat的一些核心功能。heat目前支持两种模板: 与CloudFormatior兼容的cnf目录下的模板以及自研的在hot目录下的HOT模板。 HOT模板基于YAML来展示,下面仅研究HOT模板。

写一个HOT hello world 模板
hello template file:

  1. heat_template_version: 2013-05-23  
  2.    
  3. description: Simple template to deploy a single compute instance  
  4.    
  5. resources:  
  6.     my_instance:  
  7.         type: OS::Nova::Server  
  8.         properties:  
  9.             key_name: heat_key  
  10.             image: cirros-0.3.0-i386-uec  
  11.             flavor: m1.tiny
复制代码
“heat_template_version: 2013-05-23” 是必须制定的,标识当前heat的模板版本。Resources是必须的,其中一个resources内必须至少包含一个resource定义,在该例子中的key_name, image以及flavor都是hardcoded,该问题可以通过input parameters解决。
查找上面模板相关参数的CLI过程如下:
  1. #admin tenant  
  2. stack@vm:~/devstack$ . openrc admin admin  
  3. #create heat_key keypair  
  4. stack@vm:~$ nova keypair-add heat_key  
  5. #get available image name  
  6. stack@vm:~$ nova image-list  
  7. #get instance ttype  
  8. stack@vm:~$ nova flavor-list  
复制代码
部署模板的CLI过程如下:
  1. #create stack hello-stack with helo HOT  
  2. stack@vm:~/hot-files$ heat stack-create -f ./hello hello-stack  
  3. #list stack status  
  4. stack@vm:~/hot-files$ heat stack-list  
  5. #show events status of hello-stack  
  6. stack@vm:~/hot-files$ heat event-list hello-stack  
  7. #show status of hello-stack  
  8. stack@vm:~/hot-files$ heat stack-show hello-stack  
复制代码
去硬编码,使模板更加灵活,需要加入parameters属性,这样调用模板时,可以输入相关参数,hello带input的模板如下:
  1. heat_template_version: 2013-05-23  
  2.    
  3. description: Simple template to deploy a single compute instance  
  4.    
  5. parameters:  
  6.     key_name:  
  7.         type: string  
  8.         label: Key Name  
  9.         description: Name of key-pair to be used for compute instance  
  10.     image_name:  
  11.         type: string     
  12.         label: Image Name  
  13.         description: Image to be used for compute instance  
  14.     instance_type:  
  15.         type: string  
  16.         label: Instance Type  
  17.         description: Type of instance (flavor) to be used  
  18.    
  19. outputs:  
  20.     instance_ip:  
  21.         description: the ip addresss of the deployed instance_type  
  22.         value: {get_attr: [my_instance, first_address]}  
  23.    
  24. resources:  
  25.     my_instance:  
  26.         type: OS::Nova::Server  
  27.         properties:  
  28.             key_name: { get_param: key_name }  
  29.             image: { get_param: image_name }  
  30.             flavor: { get_param: instance_type }  
复制代码
执行如下:
  1. stack@vm:~/hot-files$ heat stack-create -f ./hello_input -P "key_name=heat_key;instance_type=m1.tiny;image_name=cirros-0.3.0-i386-uec" stack-vm2
  2. stack@vm:~/hot-files$ heat stack-list
复制代码

















已有(2)人评论

跳转到指定楼层
韩克拉玛寒 发表于 2014-10-9 09:13:50
分享了,谢谢楼主
回复

使用道具 举报

guocl 发表于 2016-2-27 22:47:29
谢谢分享,但不知道这个模块有没有很大的用处。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条