Auto-Scaling Infrastructure as Code – K5 IaaSでの弾力性のあるコンピューティング

2017-10-10

Auto-Scaling Infrastructure as Code – K5 IaaSでの弾力性のあるコンピューティング

Machine-translated — the English original is authoritative.

今回の記事では、富士通のK5 IaaS AutoScaling機能のデプロイとテスト方法をご紹介します。

概要

では、K5の自動スケーリング機能とは何を指すのでしょうか? 需要に波がある仮想サーバーを想像してみてください。チケットマスターのウェブサーバーの例を挙げると、99%の時間はサーバーがアイドル状態で利用率5%で待機しています。しかし、Westlifeが再結集(そして彼らは必ずそうします)し、新ツアーのチケット販売を開始すると、かつてのティーンエイジャーたちが今では現金に余裕のある30代になり、同時にログインしてチケットを購入しようとするため、チケットマスターのサーバーは過負荷になります。[もしこの例がしっくりこない場合は、iPhoneXの発売に置き換えても構いません]。

そこで登場するのがAuto-Scaling(自動スケーリング)です – 弾力性のあるコンピューティングとも呼ばれます。Tick MasterサーバーがK5の自動スケーリング機能を使用して作成されていた場合、サーバーの負荷が上昇して事前に定義されたしきい値を超えると、K5はゼロの手間で新しいサーバーを自動的に構築し、ロードバランシングされたインスタンスプールに追加します。

さらに素晴らしいことに、すべての人がチケットを手に入れ、ロードバランシングされたサーバーの利用率が低下すると、K5は現在の需要に合わせてインフラストラクチャを自動的に縮小します。

多くの作業が必要に聞こえるかもしれませんが、良いニュースは、K5がHEATを強化し、K5のOpenStack Ceilometerを活用してこれらの作業をすべて行ってくれることです。これらの強化機能は、こちらにあるK5 Heat Guideに文書化されています。

あなたがする必要があるのは、以下のようなheatスタックを設定してデプロイすることだけです:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters

Show hidden characters

# Basic K5 template to demonstrate Fujitsu's HEAT Autoscaling enhancements
# Author: Graham J Land
# Date: 10/10/2017
heat_template_version: 2013-05-23
description:
Fujitsu Cloud Service K5 IaaS AutoScaling Example Template.
# The prerequisites for a successful deployment
parameters:
# target availability zone
az:
type: string
default: uk-1b
# server to be scaled – simple nodejs app in this demo
param_image_id:
type: string
default: bc4d2c64-1694-4488-80e2-e089bd18fc42
# t-shirt size to use
param_flavor:
type: string
default: S-1
# ssh keys to be injected into scaled servers
key_name:
type: string
description: SSH key to connect to the servers
default: LEMP-KP-AZ2
# existing router in project with external gateway configured
autoscale_router:
type: string
default: 5b29b682-df94-4178-b1b4-9bf487055787
# what actually gets built
resources:
# create a private network
autoscale_private_net_az:
type: OS::Neutron::Net
properties:
availability_zone: { get_param: az }
name: "autoscale_private_net"
# create a new subnet on the private above
autoscale_private_subnet_az:
type: OS::Neutron::Subnet
depends_on: autoscale_private_net_az
properties:
availability_zone: { get_param: az }
name: "autoscale_private_subnet_az"
network_id: { get_resource: autoscale_private_net_az }
cidr: "192.168.200.0/24"
gateway_ip: "192.168.200.254"
allocation_pools:
– start: "192.168.200.100"
end: "192.168.200.150"
dns_nameservers: ["62.60.42.9", "62.60.42.10"]
# connect an interface on the network's subnet to the existing router
az_router_interface:
type: OS::Neutron::RouterInterface
depends_on: [autoscale_private_subnet_az]
properties:
router_id: { get_param: autoscale_router }
subnet_id: { get_resource: autoscale_private_subnet_az }
# create a new security group for your PC's access
# just google "what's my ip" to determine your public NAT address
# mine was 31.53.253.24 during the demo below
security_group_01:
type: OS::Neutron::SecurityGroup
properties:
description: Add security group rules for server
name: AutoScaleServer
rules:
# allow ssh (port 22) connection from my pc
– remote_ip_prefix: 31.53.253.24/32
protocol: tcp
port_range_min: 22
port_range_max: 22
# allow ping packets from my pc
– remote_ip_prefix: 31.53.253.24/32
protocol: icmp
# create open security group for everyone to access the public LBaaS
security_group_02:
type: OS::Neutron::SecurityGroup
properties:
description: Add security group rules for server
name: AutoScaleLBaaS
rules:
# allow http (port 80) traffic from 'whole internet'
– remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 80
port_range_max: 80
# define the scaling server pool
web_server_group:
depends_on: [ az_router_interface ]
type: FCX::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones: [{get_param: az}]
LaunchConfigurationName: {get_resource: launch_config}
MinSize: '1'
MaxSize: '3'
VPCZoneIdentifier: [ {get_resource: autoscale_private_subnet_az} ]
LoadBalancerNames: [ {get_resource: eLBint} ]
# this is the actual scalable unit of deployment – the web server
launch_config:
type: FCX::AutoScaling::LaunchConfiguration
depends_on: [ security_group_01, az_router_interface ]
properties:
ImageId: { get_param: param_image_id }
InstanceType: { get_param: param_flavor }
KeyName: {get_param: key_name}
SecurityGroups: [ {get_resource: security_group_01}, {get_resource: security_group_02} ]
BlockDeviceMappingsV2: [{source_type: 'image', destination_type: 'volume', boot_index: '0', device_name: '/dev/vda', volume_size: '3',uuid: {get_param: param_image_id}, delete_on_termination: true}]
UserData:
#!/bin/bash
sudo hostname hostname
echo "Rebooting Hack"
sudo reboot
# create the load balancer that will be used to
# manage the scaling instances
eLBint:
type: FJ::ExpandableLoadBalancer::LoadBalancer
depends_on: [ security_group_01, az_router_interface ]
properties:
Subnets: [ {get_resource: autoscale_private_subnet_az} ]
Listeners:
– {LoadBalancerPort: '80', InstancePort: '80', Protocol: 'HTTP', InstanceProtocol: 'HTTP' }
HealthCheck: {Target: 'HTTP:80/', HealthyThreshold: '2', UnhealthyThreshold: '3', Interval: '5', Timeout: '5'}
Version: 2014-09-30
Scheme: public
LoadBalancerName: autoscaler
SecurityGroups: [ {get_resource: security_group_02} ]
# create the scale out policy
web_server_scaleout_policy:
type: FCX::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: {get_resource: web_server_group}
Cooldown: '10'
ScalingAdjustment: '1'
# create the scale in policy
web_server_scalein_policy:
type: FCX::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: {get_resource: web_server_group}
Cooldown: '10'
ScalingAdjustment: '-1'
# create the ALARM event which triggers when
# the server is overloaded
cpu_alarm_high:
type: OS::Ceilometer::Alarm
properties:
description: Scale-out if the average CPU > 50% for 1 minute
meter_name: fcx.compute.cpu_util
statistic: avg
period: '60'
evaluation_periods: '1'
threshold: '50'
alarm_actions:
– {get_attr: [web_server_scaleout_policy, AlarmUrl]}
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}}
comparison_operator: gt
# create the 'reset' ALARM event when services return to normal
# workloads
cpu_alarm_low:
type: OS::Ceilometer::Alarm
properties:
description: Scale-in if the average CPU < 15% for 1 minute
meter_name: fcx.compute.cpu_util
statistic: avg
period: '60'
evaluation_periods: '1'
threshold: '15'
alarm_actions:
– {get_attr: [web_server_scalein_policy, AlarmUrl]}
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}}
comparison_operator: lt

view raw
K5AutoScaling.yml
hosted with ❤ by GitHub

では、実際に試してみましょう –

テンプレートの前提条件:

az: 対象の可用性ゾーンを入力します。私の場合はuk-1bです

param_image_id:

テスト用のサーバーをお持ちでない場合、私が使用しているビルドイメージは、以下のアプリケーション /var/helloworld/helloworld.js がインストールされたシンプルなUbuntuサーバーです(「npm install –save express」を忘れないでください)–

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters

Show hidden characters

const express = require('express')
const app = express()
const serverName = require('os').hostname();
const messageTop = '
\
https://www.fujitsu.com/uk/Images/K5-climber-580x224_tcm23-2619235.jpg&quot; alt="K5 Autoscale">\

Hello from '

const messageTail = '\

\
\
'
app.get('/', function (req, res) {
res.send(messageTop + serverName + messageTail)
})
app.listen(80, function () {
console.log('Example app listening on port 80')
})

view raw
helloworld.js
hosted with ❤ by GitHub

このアプリケーションをUbuntu上でサービスとして実行するには、以下のhelloworld.confファイルをサーバーの /etc/init にコピーします。ファイル内のファイル名とパスを、上記のファイルを保存した名前と場所に合わせて調整してください –

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters

Show hidden characters

description "Fujitsu K5 IaaS AutoScaling Demo Node.js Server"
author "Graham J Land"
start on started mountall
stop on shutdown
respawn
respawn limit 99 5
script
export HOME="/root"
exec /usr//bin/nodejs /var/helloworld/helloworld.js >> /var/log/node.log 2>&1
end script
post-start script
echo "Started HelloWorld Demo NodeJS Webserver"
end script

view raw
helloworld.conf
hosted with ❤ by GitHub

param_flavor: サーバーサイズ(Tシャツサイズ)、S-1

key_name: 公開SSHキー。私はLEMP-KP-AZ2を使用しています

autoscale_router: これは、外部ゲートウェイが設定されたプロジェクト内の既存ルーターのIDです。

テンプレートの起動:

上記の前提条件を満たし、ローカル設定でテンプレートを修正したら、インフラストラクチャをデプロイする時が来ました。ここでは例としてK5ポータルを使用しますが、ネイティブのK5 APIやOpenStackクライアントを使用することもできます。

すべてがどのように組み立てられるかを見るために、ここで無料のムービーをご覧ください。

Embedded content

Happy Stacking!

Graham.

Originally published on allthingscloud.eu (2017-10-10).

← All posts