Skip to content

Instantly share code, notes, and snippets.

@zhanghui9700
Last active September 25, 2017 00:30
Show Gist options
  • Save zhanghui9700/135e22509c960d0bbd97ceb7d6256100 to your computer and use it in GitHub Desktop.
Save zhanghui9700/135e22509c960d0bbd97ceb7d6256100 to your computer and use it in GitHub Desktop.
heat tutorial
@zhanghui9700
Copy link
Author

orchestration by openstack heat 05-A-auto scaling

OS::Heat::AutoScalingGroup

root@node-6:~/heat/auto-scale# cat instance.yaml

heat_template_version: 2014-10-16  
description: A simple server. 
resources:  
  server:
    type: OS::Nova::Server
    properties:
      image: TestVM
      flavor: m1.micro
      networks:
        - network: admin_internal_net
      user_data_format: RAW
      user_data: |
        #!/bin/sh
        while [ 1 ] ; do echo $((13**99)) 1>/dev/null 2>&1; done

root@node-6:~/heat/auto-scale# cat asg_of_stacks.yaml

heat_template_version: 2013-05-23

description: >
  This is a very simple template that illustrates the basic features
  of OS::Heat::AutoScalingGroup and demonstrates that these features
  are available even when the scaled resource is a nested stack.  By
  virtue of its simplicity this example should be usable in many
  contexts.  In particular, this example does not require Neutron nor
  a load balancer nor any particular support for software in the VMs.
  In fact, the VMs in this example do not actually do anything.  This
  example does no automatic scaling, but does discuss manual scaling.
  For a more complete example, see autoscaling.yaml.

resources:
  asg:
    type: OS::Heat::AutoScalingGroup
    properties:
      resource:
        type: instance.yaml
      min_size: 1
      desired_capacity: 3
      max_size: 5

  scale_up_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: asg}
      cooldown: 60
      scaling_adjustment: 1

  scale_dn_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: asg}
      cooldown: 60
      scaling_adjustment: '-1'

outputs:
  scale_up_url:
    description: >
      This URL is the webhook to scale up the group.  You can invoke
      the scale-up operation by doing an HTTP POST to this URL; no
      body nor extra headers are needed.
    value: {get_attr: [scale_up_policy, alarm_url]}
  scale_dn_url:
    description: >
      This URL is the webhook to scale down the group.  You can invoke
      the scale-down operation by doing an HTTP POST to this URL; no
      body nor extra headers are needed.
    value: {get_attr: [scale_dn_policy, alarm_url]}

查看scale的web hook url

如果有独立的监控系统,OS::Heat::ScalingPolicy的alarm url属性,是个非常有意义的实现。

root@node-6:~/heat/auto-scale# openstack stack output show asg-stack --all

+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field        | Value                                                                                                                                                                                                                                                                                                                                                                                                       |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| scale_dn_url | {                                                                                                                                                                                                                                                                                                                                                                                                           |
|              |   "output_value": "http://192.168.32.8:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3A828076867d8242c98423c6064a7f4e6e%3Astacks%2Fasg-stack%2Ffee39f2c-cfb9-466e-a331-d087b385cc36%2Fresources%2Fscale_dn_policy?Timestamp=2017-01-09T09%3A35%3A37Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=61ef2253f40e4962a3e8c4def51d0def&SignatureVersion=2&Signature=NQx9BDE1Gf5GcZDvVjmPACwHhKv5ZwyR8xNxp%2BKErtY%3D",  |
|              |   "output_key": "scale_dn_url",                                                                                                                                                                                                                                                                                                                                                                             |
|              |   "description": "This URL is the webhook to scale down the group.  You can invoke the scale-down operation by doing an HTTP POST to this URL; no body nor extra headers are needed.\n"                                                                                                                                                                                                                     |
|              | }                                                                                                                                                                                                                                                                                                                                                                                                           |
| scale_up_url | {                                                                                                                                                                                                                                                                                                                                                                                                           |
|              |   "output_value": "http://192.168.32.8:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3A828076867d8242c98423c6064a7f4e6e%3Astacks%2Fasg-stack%2Ffee39f2c-cfb9-466e-a331-d087b385cc36%2Fresources%2Fscale_up_policy?Timestamp=2017-01-09T09%3A35%3A37Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=83737133a505471493d4d88bebbdbb0d&SignatureVersion=2&Signature=eCgV6KfQv%2FKSUsE6yPuULdWBwljHi7dHHn9rzrSS4wg%3D",  |
|              |   "output_key": "scale_up_url",                                                                                                                                                                                                                                                                                                                                                                             |
|              |   "description": "This URL is the webhook to scale up the group.  You can invoke the scale-up operation by doing an HTTP POST to this URL; no body nor extra headers are needed.\n"                                                                                                                                                                                                                         |
|              | }                                                                                                                                                                                                                                                                                                                                                                                                           |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

扩容集群规模

root@node-6:~/heat/auto-scale# curl -X POST 'http://192.168.32.8:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3A828076867d8242c98423c6064a7f4e6e%3Astacks%2Fasg-stack%2Ffee39f2c-cfb9-466e-a331-d087b385cc36%2Fresources%2Fscale_up_policy?Timestamp=2017-01-09T09%3A35%3A37Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=83737133a505471493d4d88bebbdbb0d&SignatureVersion=2&Signature=eCgV6KfQv%2FKSUsE6yPuULdWBwljHi7dHHn9rzrSS4wg%3D'

收缩集群规模

root@node-6:~# curl -X POST 'http://192.168.32.8:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3A828076867d8242c98423c6064a7f4e6e%3Astacks%2Fasg-stack%2Ffee39f2c-cfb9-466e-a331-d087b385cc36%2Fresources%2Fscale_dn_policy?Timestamp=2017-01-09T09%3A35%3A37Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=61ef2253f40e4962a3e8c4def51d0def&SignatureVersion=2&Signature=NQx9BDE1Gf5GcZDvVjmPACwHhKv5ZwyR8xNxp%2BKErtY%3D'

root@node-6:~/heat/auto-scale# openstack stack resource list asg-stack -n 1

# 多次收缩在会停留在auto-scale-group的min size大小
+-----------------+--------------------------------------+--------------------------------------------+-----------------+---------------------+----------------------------+
| resource_name   | physical_resource_id                 | resource_type                              | resource_status | updated_time        | stack_name                 |
+-----------------+--------------------------------------+--------------------------------------------+-----------------+---------------------+----------------------------+
| scale_up_policy | 7d07239923f046c58c01a739a5bce1d7     | OS::Heat::ScalingPolicy                    | CREATE_COMPLETE | 2017-01-09T09:35:37 | asg-stack                  |
| asg             | da32c720-9f5d-4cbe-addb-81027c55d2f3 | OS::Heat::AutoScalingGroup                 | CREATE_COMPLETE | 2017-01-09T09:35:37 | asg-stack                  |
| 4gpvzswknzwn    | 64e2fc72-b476-4fa0-939a-d8b42f86b3d4 | file:///root/heat/auto-scale/instance.yaml | UPDATE_COMPLETE | 2017-01-09T10:27:49 | asg-stack-asg-gfjjpij7j7ii |
| scale_dn_policy | 6b5a39709fc046d7b39705f8ae1ddfb9     | OS::Heat::ScalingPolicy                    | CREATE_COMPLETE | 2017-01-09T09:35:37 | asg-stack                  |
+-----------------+--------------------------------------+--------------------------------------------+-----------------+---------------------+----------------------------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment