1.2. 예제: CPU 사용량에 따른 자동 스케일링
이 예제에서 오케스트레이션은 원격 분석 데이터를 검사하고 CPU 사용량이 많은 응답으로 인스턴스 수를 자동으로 늘립니다. 스택 템플릿과 환경 템플릿을 생성하여 규칙 및 후속 구성을 정의합니다. 이 예제에서는 네트워크와 같은 기존 리소스를 사용하며 사용자 환경의 사용자와 다를 수 있는 이름을 사용합니다.
cpu_util 지표는 더 이상 사용되지 않으며 Red Hat OpenStack Platform에서 제거되었습니다.
절차
인스턴스 플레이버, 네트워킹 구성 및 이미지 유형을 설명하는 환경 템플릿을 만듭니다. 템플릿을
/home/<user>/stacks/example1/cirros.yaml파일에 저장합니다.<user>변수를 실제 사용자 이름으로 바꿉니다.heat_template_version: 2016-10-14 description: Template to spawn an cirros instance. parameters: metadata: type: json image: type: string description: image used to create instance default: cirros flavor: type: string description: instance flavor to be used default: m1.tiny key_name: type: string description: keypair to be used default: mykeypair network: type: string description: project network to attach instance to default: internal1 external_network: type: string description: network used for floating IPs default: external_network resources: server: type: OS::Nova::Server properties: block_device_mapping: - device_name: vda delete_on_termination: true volume_id: { get_resource: volume } flavor: {get_param: flavor} key_name: {get_param: key_name} metadata: {get_param: metadata} networks: - port: { get_resource: port } port: type: OS::Neutron::Port properties: network: {get_param: network} security_groups: - default floating_ip: type: OS::Neutron::FloatingIP properties: floating_network: {get_param: external_network} floating_ip_assoc: type: OS::Neutron::FloatingIPAssociation properties: floatingip_id: { get_resource: floating_ip } port_id: { get_resource: port } volume: type: OS::Cinder::Volume properties: image: {get_param: image} size: 1오케스트레이션 리소스를
~/stacks/example1/environment.yaml에 등록합니다.resource_registry: "OS::Nova::Server::Cirros": ~/stacks/example1/cirros.yaml스택 템플릿을 생성합니다. 조사할 CPU 임계값과 추가할 인스턴스 수를 설명합니다. 이 템플릿에 참여할 수 있는 최소 및 최대 인스턴스 수를 정의하는 인스턴스 그룹도 생성됩니다.
참고cpu_util지표는 더 이상 사용되지 않으며 Red Hat OpenStack Platform에서 제거되었습니다. 동등한 기능을 얻으려면 누적CPU지표와rate:mean집계 방법을 포함하는 보관 정책을 사용합니다. 예를 들면ceilometer-high-rate및ceilometer-low-rate입니다. CPU 사용률 알람에 대해cpu지표를 사용하려면 임계값을 %에서 ns로 변환해야 합니다. 공식은 time_ns = ✓,000 x {granularity} x {percentage_in_decimal}입니다. 예를 들어 세분성이 1인 80%의 임계값의 경우 임계값은 ,000 x 1 x✓ = 800,000,000.0입니다.다음 값을
~/stacks/example1/template.yaml에 저장합니다.heat_template_version: 2016-10-14 description: Example auto scale group, policy and alarm resources: scaleup_group: type: OS::Heat::AutoScalingGroup properties: cooldown: 300 desired_capacity: 1 max_size: 3 min_size: 1 resource: type: OS::Nova::Server::Cirros properties: metadata: {"metering.server_group": {get_param: "OS::stack_id"}} scaleup_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: scaleup_group } cooldown: 300 scaling_adjustment: 1 scaledown_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: scaleup_group } cooldown: 300 scaling_adjustment: -1 cpu_alarm_high: type: OS::Aodh::GnocchiAggregationByResourcesAlarm properties: description: Scale up if CPU > 80% metric: cpu aggregation_method: rate:mean granularity: 1 evaluation_periods: 3 threshold: 800000000.0 resource_type: instance comparison_operator: gt alarm_actions: - str_replace: template: trust+url params: url: {get_attr: [scaleup_policy, signal_url]} query: str_replace: template: '{"=": {"server_group": "stack_id"}}' params: stack_id: {get_param: "OS::stack_id"} cpu_alarm_low: type: OS::Aodh::GnocchiAggregationByResourcesAlarm properties: metric: cpu aggregation_method: rate:mean granularity: 600 evaluation_periods: 3 threshold: 200000000.0 resource_type: instance comparison_operator: lt alarm_actions: - str_replace: template: trust+url params: url: {get_attr: [scaledown_policy, signal_url]} query: str_replace: template: '{"=": {"server_group": "stack_id"}}' params: stack_id: {get_param: "OS::stack_id"} outputs: scaleup_policy_signal_url: value: {get_attr: [scaleup_policy, signal_url]} scaledown_policy_signal_url: value: {get_attr: [scaledown_policy, signal_url]}환경을 빌드하고 인스턴스를 배포합니다.
$ openstack stack create -t template.yaml -e environment.yaml example +---------------------+--------------------------------------------+ | Field | Value | +---------------------+--------------------------------------------+ | id | 248a98bb-f56e-4934-a281-fffde62d78d8 | | stack_name | example | | description | Example auto scale group, policy and alarm | | creation_time | 2017-03-06T15:00:29Z | | updated_time | None | | stack_status | CREATE_IN_PROGRESS | | stack_status_reason | Stack CREATE started | +---------------------+--------------------------------------------+
오케스트레이션에서 스택을 생성하고
scaleup_group정의의min_size매개 변수에 정의된 대로 정의된 최소 cirros 인스턴스를 시작합니다. 인스턴스가 성공적으로 생성되었는지 확인합니다.$ openstack server list +--------------------------------------+-------------------------------------------------------+--------+------------+-------------+-------------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+-------------------------------------------------------+--------+------------+-------------+-------------------------------------+ | e1524f65-5be6-49e4-8501-e5e5d812c612 | ex-3gax-5f3a4og5cwn2-png47w3u2vjd-server-vaajhuv4mj3j | ACTIVE | - | Running | internal1=10.10.10.9, 192.168.122.8 | +--------------------------------------+-------------------------------------------------------+--------+------------+-------------+-------------------------------------+
오케스트레이션에서는 cpu_alarm_
high 및 cpu_알람도 생성합니다. 트리거가 있는지 확인합니다.alarm_low에 정의된 대로 확장 또는 축소 이벤트를 트리거하는 두 개의 cpu$ openstack alarm list +--------------------------------------+--------------------------------------------+-------------------------------------+-------------------+----------+---------+ | alarm_id | type | name | state | severity | enabled | +--------------------------------------+--------------------------------------------+-------------------------------------+-------------------+----------+---------+ | 022f707d-46cc-4d39-a0b2-afd2fc7ab86a | gnocchi_aggregation_by_resources_threshold | example-cpu_alarm_high-odj77qpbld7j | insufficient data | low | True | | 46ed2c50-e05a-44d8-b6f6-f1ebd83af913 | gnocchi_aggregation_by_resources_threshold | example-cpu_alarm_low-m37jvnm56x2t | insufficient data | low | True | +--------------------------------------+--------------------------------------------+-------------------------------------+-------------------+----------+---------+