자동 크기 조정을 사용하면 애플리케이션의 변화하는 부하를 처리할 수 있는 적절한 양의 리소스를 실행할 수 있습니다. Azure 포털, Azure CLI, Azure PowerShell 또는 ARM 또는 Bicep 템플릿을 사용하여 자동 크기 조정을 구성할 수 있습니다.
이 문서에서는 PowerShell을 사용하여 가상 머신 확장 집합에 대한 자동 크기 조정을 구성하는 방법을 보여 줍니다. 구성은 다음 단계를 사용합니다.
- 자동 크기 조정이 가능한 스케일 세트를 만듭니다.
- 스케일 인 및 스케일 아웃하는 규칙을 만듭니다.
- 사용자 규칙을 사용하는 프로필을 만듭니다.
- 자동 크기 조정 설정을 적용합니다.
- 알림을 사용하여 자동 크기 조정 설정을 업데이트합니다.
필수 조건
PowerShell을 사용하여 자동 크기 조정을 구성하려면 활성 구독이 있는 Azure 계정이 필요합니다. 무료로 계정을 만들 수 있습니다.
환경 설정
Azure Cloud Shell PowerShell을 사용합니다.
비고
원하는 구독을 선택한 상태에서 동일한 PowerShell 세션에서 예제를 실행합니다.
# Set variables
$resourceGroupName = "<ResourceGroupName>"
$vmssName = "<VirtualMachineScaleSetName>"
$autoscaleName = "<AutoscaleSettingName>"
$azureRegion = "<AzureRegion>"
$virtualNetworkName = "<VirtualNetworkName>"
$subnetName = "<SubnetName>"
$publicIpAddressName = "<PublicIpAddressName>"
$loadBalancerName = "<LoadBalancerName>"
# Get the subscription ID from the current Azure PowerShell context
$subscriptionId = (Get-AzContext).Subscription.Id
# Build virtual machine scale set resource ID
$vmssPath = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName"
$vmssProvider = "Microsoft.Compute/virtualMachineScaleSets/$vmssName"
$vmssResourceId = "$vmssPath/providers/$vmssProvider"
가상 머신 크기 집합 만들기
다음 Azure PowerShell 예제에서는 New-AzVmss 및 New-AzResourceGroup cmdlet을 사용합니다.
비고
완료되면 예제의 리소스를 삭제할 수 있도록 이 예제에 전용 리소스 그룹을 사용합니다.
이 예제에서는 공용 IP 주소를 만듭니다. 관리 액세스의 경우 RDP 또는 SSH 포트를 인터넷에 노출하는 대신 Azure Bastion 사용합니다.
# Create the resource group
New-AzResourceGroup -ResourceGroupName $resourceGroupName -Location $azureRegion
# Get credentials for the virtual machine scale set
$vmCredential = Get-Credential
# Define parameters for New-AzVmss
$newAzVmssParams = @{
ResourceGroupName = $resourceGroupName
Location = $azureRegion
VMScaleSetName = $vmssName
Credential = $vmCredential
VirtualNetworkName = $virtualNetworkName
SubnetName = $subnetName
PublicIpAddressName = $publicIpAddressName
LoadBalancerName = $loadBalancerName
OrchestrationMode = "Flexible"
}
# Create the virtual machine scale set
New-AzVmss @newAzVmssParams
자동 크기 조정 설정 만들기
PowerShell을 사용하여 자동 크기 조정 설정을 만들려면 아래 시퀀스를 따릅니다.
-
New-AzAutoscaleScaleRuleObject를 사용하여 규칙을 만듭니다. -
New-AzAutoscaleProfileObject를 사용하여 프로필을 만듭니다. -
New-AzAutoscaleSetting를 사용하여 자동 크기 조정 설정을 만듭니다. -
Update-AzAutoscaleSetting을 사용하여 설정을 업데이트합니다.
규칙 만들기
스케일 인 및 스케일 아웃 규칙을 만든 다음 프로필과 연결합니다.
다음 Azure PowerShell 예제에서는 cmdlet을 New-AzAutoscaleScaleRuleObject 사용합니다.
비고
다음 두 가지 규칙을 만듭니다.
- CPU 백분율이 70%를 초과하면 스케일 아웃합니다.
- 백분율 CPU가 30% 미만인 경우 축소합니다.
# Define parameters for New-AzAutoscaleScaleRuleObject
$newAzAutoscaleScaleRuleObjectParams = @{
MetricTriggerMetricName = "Percentage CPU"
MetricTriggerMetricResourceUri = $vmssResourceId
MetricTriggerTimeGrain = New-TimeSpan -Minutes 1
MetricTriggerStatistic = "Average"
MetricTriggerTimeWindow = New-TimeSpan -Minutes 5
MetricTriggerTimeAggregation = "Average"
MetricTriggerOperator = "GreaterThan"
MetricTriggerThreshold = 70
MetricTriggerDividePerInstance = $false
ScaleActionDirection = "Increase"
ScaleActionType = "ChangeCount"
ScaleActionValue = "1"
ScaleActionCooldown = New-TimeSpan -Minutes 5
}
$scaleOutRule = New-AzAutoscaleScaleRuleObject @newAzAutoscaleScaleRuleObjectParams
# Define parameters for New-AzAutoscaleScaleRuleObject
$newAzAutoscaleScaleRuleObjectParams = @{
MetricTriggerMetricName = "Percentage CPU"
MetricTriggerMetricResourceUri = $vmssResourceId
MetricTriggerTimeGrain = New-TimeSpan -Minutes 1
MetricTriggerStatistic = "Average"
MetricTriggerTimeWindow = New-TimeSpan -Minutes 5
MetricTriggerTimeAggregation = "Average"
MetricTriggerOperator = "LessThan"
MetricTriggerThreshold = 30
MetricTriggerDividePerInstance = $false
ScaleActionDirection = "Decrease"
ScaleActionType = "ChangeCount"
ScaleActionValue = "1"
ScaleActionCooldown = New-TimeSpan -Minutes 5
}
$scaleInRule = New-AzAutoscaleScaleRuleObject @newAzAutoscaleScaleRuleObjectParams
아래 표에서는 New-AzAutoscaleScaleRuleObject cmdlet에 사용되는 매개 변수를 설명합니다.
| 매개 변수 | 설명 |
|---|---|
MetricTriggerMetricName |
자동 크기 조정 트리거 메트릭 설정 |
MetricTriggerMetricResourceUri |
MetricTriggerMetricName 메트릭이 속한 리소스를 지정합니다.
MetricTriggerMetricResourceUri는 크기 조정되는 리소스뿐만 아니라 모든 리소스일 수 있습니다. 예를 들어, 부하 분산 장치, 데이터베이스 또는 확장 집합 자체에서 만들어진 메트릭을 기반으로 Virtual Machine Scale Sets의 크기를 조정할 수 있습니다. 지정된 MetricTriggerMetricName에 대해 MetricTriggerMetricResourceUri이 존재해야 합니다. |
MetricTriggerTimeGrain |
규칙이 모니터링하는 메트릭의 샘플링 빈도입니다.
MetricTriggerTimeGrain은 지정된 메트릭에 대해 미리 정의된 값 중 하나여야 하며 12시간에서 1분 사이여야 합니다. 예를 들어, MetricTriggerTimeGrain = PT1M"*는 메트릭이 1분마다 샘플링되고 MetricTriggerStatistic에 지정된 집계 메서드를 사용하여 집계된다는 의미입니다. |
MetricTriggerTimeAggregation |
timeGrain 기간 내 집계 방법입니다. 예를 들어, statistic = "Average" 및 timeGrain = "PT1M"은 메트릭이 평균을 구하여 1분마다 집계된다는 의미입니다. |
MetricTriggerStatistic |
샘플링된 메트릭을 집계하는 데 사용되는 집계 방법입니다. 예를 들어, TimeAggregation = "Average"는 평균을 구하여 샘플링된 메트릭을 집계합니다. |
MetricTriggerTimeWindow |
자동 크기 조정 엔진이 메트릭을 집계하기 위해 다시 확인하는 시간입니다. 이 값은 리소스에 따라 달라지는 메트릭 컬렉션 지연보다 커야 합니다. 5분에서 12시간 사이여야 합니다. 예를 들어, 10분은 자동 크기 조정이 실행될 때마다 지난 10분 동안의 메트릭을 쿼리한다는 의미입니다. 이 기능을 사용하면 메트릭을 안정화하고 일시적인 급증에 대한 반응을 방지할 수 있습니다. |
MetricTriggerThreshold |
규모 이벤트를 트리거하는 메트릭의 값을 정의합니다. |
MetricTriggerOperator |
메트릭 값을 평가할 때 사용할 논리적 비교 연산을 지정합니다. |
MetricTriggerDividePerInstance |
true로 설정하면 트리거 메트릭을 총 인스턴스 수로 나눕니다. 예를 들어, 메시지 수가 300개이고 실행 중인 인스턴스가 5개라면 계산된 메트릭 값은 인스턴스당 메시지 60개입니다. 이 속성은 모든 메트릭에 적용할 수 없습니다. |
ScaleActionDirection |
스케일 인 또는 스케일 아웃을 지정합니다. 유효한 값은 Increase 및 Decrease입니다. |
ScaleActionType |
특정 인스턴스 수만큼 크기 조정하거나, 특정 인스턴스 수로 크기 조정하거나, 현재 인스턴스 수의 백분율로 크기 조정합니다. 유효한 값은 ChangeCount, ExactCount 및 PercentChangeCount입니다. |
ScaleActionCooldown |
크기 조정 작업이 수행된 후 이 규칙이 다른 크기 조정 작업을 시작할 수 있게 되기까지 반드시 지나야 하는 최소 시간입니다. 자동 크기 조정은 각 규칙의 쿨다운을 독립적으로 확인합니다. 쿨다운을 사용하면 메트릭이 안정화되고 펄럭이는 것을 방지할 수 있습니다. |
기본 자동 크기 조정 프로필을 만들고 규칙을 연결합니다.
스케일 규칙을 정의한 후 프로필을 만듭니다. 프로필은 기본, 상한 및 하한 인스턴스 수 제한과 관련 규칙이 적용될 수 있는 시간을 지정합니다.
다음 Azure PowerShell 예제에서는 cmdlet을 New-AzAutoscaleProfileObject 사용합니다.
비고
이 프로필은 기본 프로필이므로 일정 매개 변수가 없습니다. 기본 프로필은 다른 프로필이 활성 상태가 아닌 시간에는 활성화됩니다.
# Define parameters for New-AzAutoscaleProfileObject
$newAzAutoscaleProfileObjectParams = @{
Name = "default"
CapacityDefault = "1"
CapacityMaximum = "10"
CapacityMinimum = "1"
Rule = @($scaleOutRule, $scaleInRule)
}
$defaultProfile = New-AzAutoscaleProfileObject @newAzAutoscaleProfileObjectParams
아래 표에서는 New-AzAutoscaleProfileObject cmdlet에 사용되는 매개 변수를 설명합니다.
| 매개 변수 | 설명 |
|---|---|
CapacityDefault |
메트릭을 평가할 수 없는 경우의 인스턴스 수입니다. 기본값은 현재 인스턴스 수가 기본값보다 작은 경우에만 사용됩니다. |
CapacityMaximum |
리소스의 최대 인스턴스 수입니다. 최대 인스턴스 수는 구독에서 사용 가능한 코어 수에 따라 추가로 제한됩니다. |
CapacityMinimum |
리소스의 최소 인스턴스 수입니다. |
FixedDateEnd |
ISO 8601 형식의 프로필 종료 시간입니다. |
FixedDateStart |
ISO 8601 형식의 프로필 시작 시간입니다. |
Rule |
이 프로필이 활성화될 때 조정 작업에 대한 트리거 및 매개 변수를 제공하는 규칙 컬렉션입니다. 최대 10개의 쉼표로 구분된 규칙을 지정할 수 있습니다. |
RecurrenceFrequency |
예약된 프로필이 적용되는 빈도입니다. 이 값은 week여야 합니다. |
ScheduleDay |
되풀이 일정을 지정할 때 프로필이 적용되는 날짜 컬렉션입니다. 가능한 값은 일요일부터 토요일까지입니다. 되풀이 일정에 대한 자세한 내용은 PowerShell을 사용한 되풀이 프로필을 참조하세요. |
ScheduleHour |
프로필이 적용되는 시간 컬렉션입니다. 지원되는 값은 0~23입니다. |
ScheduleMinute |
프로필이 적용되는 시점 모음입니다. |
ScheduleTimeZone |
프로필의 시간에 대한 시간대입니다. |
자동 크기 조정 설정 적용
규칙 및 프로필을 정의한 후 자동 크기 조정 설정을 적용합니다. 기존 자동 크기 조정 설정을 업데이트하려면 Update-AzAutoscaleSetting를 사용합니다.
다음 Azure PowerShell 예제에서는 cmdlet을 New-AzAutoscaleSetting 사용합니다.
# Define parameters for New-AzAutoscaleSetting
$newAzAutoscaleSettingParams = @{
Name = $autoscaleName
ResourceGroupName = $resourceGroupName
Location = $azureRegion
Profile = @($defaultProfile)
Enabled = $true
PropertiesName = $autoscaleName
TargetResourceUri = $vmssResourceId
}
# Create the autoscale setting
New-AzAutoscaleSetting @newAzAutoscaleSettingParams
자동 크기 조정 설정에 알림 추가
자동 크기 조정 설정에 알림을 추가하여 웹후크를 트리거하거나 크기 조정 이벤트가 발생할 때 전자 메일 알림을 보냅니다.
다음 Azure PowerShell 예제에서는 cmdlet을 New-AzAutoscaleWebhookNotificationObject 사용합니다.
# Set variables
$webhookUri = "<WebhookUri>"
# Create the webhook notification
$webhook = New-AzAutoscaleWebhookNotificationObject -Property @{} -ServiceUri $webhookUri
다음 Azure PowerShell 예제에서는 New-AzAutoscaleNotificationObject cmdlet을 사용하여 웹후크 및 전자 메일 알림을 구성합니다.
비고
웹후크용 HTTPS 엔드포인트를 사용합니다.
# Set variables
$notificationEmail = "<NotificationEmail>"
# Define parameters for New-AzAutoscaleNotificationObject
$newAzAutoscaleNotificationObjectParams = @{
EmailCustomEmail = @($notificationEmail)
EmailSendToSubscriptionAdministrator = $true
EmailSendToSubscriptionCoAdministrator = $true
Webhook = @($webhook)
}
$notification = New-AzAutoscaleNotificationObject @newAzAutoscaleNotificationObjectParams
다음 Azure PowerShell 예제에서는 Update-AzAutoscaleSetting cmdlet을 사용하여 알림을 적용합니다.
# Define parameters for Update-AzAutoscaleSetting
$updateAzAutoscaleSettingParams = @{
Name = $autoscaleName
ResourceGroupName = $resourceGroupName
Notification = @($notification)
}
# Update the autoscale notification
Update-AzAutoscaleSetting @updateAzAutoscaleSettingParams
자동 크기 조정 설정 검토
다음 Azure PowerShell 예제에서는 Get-AzAutoscaleSetting cmdlet을 사용하여 자동 크기 조정 설정을 검색합니다.
# Define parameters for Get-AzAutoscaleSetting
$getAzAutoscaleSettingParams = @{
ResourceGroupName = $resourceGroupName
Name = $autoscaleName
}
$autoscaleSetting = Get-AzAutoscaleSetting @getAzAutoscaleSettingParams
$autoscaleSetting | Select-Object -Property *
다음 Azure PowerShell 예제에서는 cmdlet을 Get-AzAutoscaleHistory 사용합니다.
비고
확장 집합의 리소스 ID가 아닌 자동 크기 조정 설정의 기록을 쿼리합니다.
# Build autoscale setting resource ID
$autoscalePath = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName"
$autoscaleProvider = "Microsoft.Insights/autoscaleSettings/$autoscaleName"
$autoscaleResourceId = "$autoscalePath/providers/$autoscaleProvider"
# Retrieve the autoscale history
Get-AzAutoscaleHistory -ResourceId $autoscaleResourceId
예약 및 되풀이 프로필
비고
업데이트 Profile할 때 유지하려는 모든 프로필을 포함합니다. 다음 예제에서는 이 문서의 앞부분에서 만든 설정에 프로필을 추가합니다. 다른 자동 크기 조정 설정에 맞게 조정할 때 다른 프로필을 유지하세요.
특별 이벤트에 대한 예정된 프로필 추가
특정 이벤트에 대해 다르게 크기를 조정하려면 자동 크기 조정 프로필을 설정합니다. 예를 들어, 수요가 평소보다 높아지는 날에는 최대 및 최소 인스턴스 한도가 증가된 프로필을 만듭니다.
다음 Azure PowerShell 예제에서는 Update-AzAutoscaleSetting 및 New-AzAutoscaleProfileObject cmdlet을 사용합니다.
비고
다음 예제에서는 앞에서 정의한 기본 프로필과 동일한 규칙을 사용하지만 특정 날짜에 대한 새 인스턴스 제한을 설정합니다. 새 프로필에 사용할 다른 규칙을 구성할 수도 있습니다. 시작 및 끝 값은 UTC에서 ISO 8601 타임스탬프를 사용합니다.
# Set variables
$startTime = "<StartTime>"
$endTime = "<EndTime>"
# Define parameters for New-AzAutoscaleProfileObject
$newAzAutoscaleProfileObjectParams = @{
Name = "High-demand-day"
CapacityDefault = "7"
CapacityMaximum = "30"
CapacityMinimum = "5"
FixedDateEnd = [datetime]::Parse($endTime)
FixedDateStart = [datetime]::Parse($startTime)
FixedDateTimeZone = "UTC"
Rule = @($scaleOutRule, $scaleInRule)
}
$highDemandDay = New-AzAutoscaleProfileObject @newAzAutoscaleProfileObjectParams
# Define parameters for Update-AzAutoscaleSetting
$updateAzAutoscaleSettingParams = @{
Name = $autoscaleName
ResourceGroupName = $resourceGroupName
Profile = @($defaultProfile, $highDemandDay)
}
# Update the autoscale profiles
Update-AzAutoscaleSetting @updateAzAutoscaleSettingParams
되풀이 예약 프로필 추가
반복 프로필을 사용하면 매주 반복되는 스케일링 프로필을 예약할 수 있습니다.
예약된 프로필에는 시작 날짜와 종료 날짜가 있지만 되풀이 프로필에는 종료 시간이 없습니다. 프로필은 다음 프로필이 시작될 때까지 활성 상태로 유지됩니다. 따라서 되풀이 프로필을 만들 때 이전 되풀이 프로필을 완료하려고 할 때 시작되는 되풀이 기본 프로필을 만들어야 합니다.
다음 Azure PowerShell 예제에서는 Update-AzAutoscaleSetting 및 New-AzAutoscaleProfileObject cmdlet을 사용합니다.
비고
예를 들어, 주말에는 금요일 밤부터 월요일 아침까지 단일 인스턴스로 크기 조정합니다. 금요일 밤에 시작하여 월요일 아침에 끝나는 주말 프로필을 구성하려면 금요일 밤에 시작하는 프로필을 만든 다음 월요일 아침에 시작하는 기본 설정으로 되풀이 프로필을 만듭니다.
이전 단계의 기본 및 고정 날짜 프로필을 유지하면서 주말 프로필을 종료하는 되풀이 기본 프로필과 주말 프로필을 만듭니다.
# Define parameters for New-AzAutoscaleProfileObject
$newAzAutoscaleProfileObjectParams = @{
Name = "Weekend"
CapacityDefault = "1"
CapacityMaximum = "1"
CapacityMinimum = "1"
RecurrenceFrequency = "Week"
ScheduleDay = @("Friday")
ScheduleHour = @(22)
ScheduleMinute = @(0)
ScheduleTimeZone = "Pacific Standard Time"
Rule = @($scaleOutRule, $scaleInRule)
}
$fridayProfile = New-AzAutoscaleProfileObject @newAzAutoscaleProfileObjectParams
# Define parameters for New-AzAutoscaleProfileObject
$newAzAutoscaleProfileObjectParams = @{
Name = "default recurring profile"
CapacityDefault = "2"
CapacityMaximum = "10"
CapacityMinimum = "2"
RecurrenceFrequency = "Week"
ScheduleDay = @("Monday")
ScheduleHour = @(0)
ScheduleMinute = @(0)
ScheduleTimeZone = "Pacific Standard Time"
Rule = @($scaleOutRule, $scaleInRule)
}
$defaultRecurringProfile = New-AzAutoscaleProfileObject @newAzAutoscaleProfileObjectParams
# Define parameters for Update-AzAutoscaleSetting
$updateAzAutoscaleSettingParams = @{
Name = $autoscaleName
ResourceGroupName = $resourceGroupName
Profile = @(
$defaultProfile
$highDemandDay
$defaultRecurringProfile
$fridayProfile
)
}
# Update the autoscale profiles
Update-AzAutoscaleSetting @updateAzAutoscaleSettingParams
예약된 프로필에 대한 자세한 내용은 여러 프로필이 있는 Autoscale을(를) 참조하세요.
기타 자동 크기 조정 명령
자동 크기 조정에 대한 PowerShell cmdlet의 전체 목록은 PowerShell 모듈 브라우저를 참조하세요.
리소스 정리
이 자습서에서 만든 리소스를 정리하려면 만든 전용 리소스 그룹을 삭제합니다. 다음 cmdlet은 리소스 그룹과 해당 리소스를 모두 삭제합니다.
다음 Azure PowerShell 예제에서는 cmdlet을 Remove-AzResourceGroup 사용합니다.
# Delete the example resource group
Remove-AzResourceGroup -Name $resourceGroupName