This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
10-create-autoscaler.sh
61 lines (52 loc) · 2.36 KB
/
10-create-autoscaler.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#############################################################################################
# Ensure you have logged in to Azure with your credentials prior to running this script
# az login
# Ensure that you have the Azure subscription ID, it should show up after you have logged in and it has the format:
# "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
# Ensure that you have a virtual machine scale set already in place
#############################################################################################
#############################################################################################
# General variables used in the different Azure CLI commands run from this script
export YOURSUBSCRIPTIONID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
export RESOURCEGROUPNAME=myResourceGroup
export REGIONNAME=japanwest
export PREFIX=myGameBackend
# Variables for setting up the virtual machine scale set autoscaler
export VMSSNAME=${PREFIX}VMSS
export VMSSVMTOCREATE=2
export VMSSAUTOSCALERNAME=${PREFIX}Autoscaler
export VMSSAUTOSCALERCRITERIA=Percentage CPU
export VMSSAUTOSCALERMAXCOUNT=10
export VMSSAUTOSCALERMINCOUNT=$VMSSVMTOCREATE
export VMSSAUTOSCALERUPTRIGGER=50 avg 5m
export VMSSAUTOSCALERDOWNTRIGGER=30 avg 5m
export VMSSAUTOSCALEROUTINCREASE=1
export VMSSAUTOSCALERINDECREASE=1
#############################################################################################
# Connect to Azure
az login
# Set the Azure subscription
az account set \
--subscription $YOURSUBSCRIPTIONID
echo Defining the autoscaling profile
az monitor autoscale create \
--resource-group $RESOURCEGROUPNAME \
--resource $VMSSNAME \
--resource-type Microsoft.Compute/virtualMachineScaleSets \
--name $VMSSAUTOSCALERNAME \
--min-count $VMSSAUTOSCALERMINCOUNT \
--max-count $VMSSAUTOSCALERMAXCOUNT \
--count $VMSSVMTOCREATE
echo Enabling virtual machine autoscaler for scaling out
az monitor autoscale rule create \
--resource-group $RESOURCEGROUPNAME \
--autoscale-name $VMSSAUTOSCALERNAME \
--condition "${VMSSAUTOSCALERCRITERIA} > ${VMSSAUTOSCALERUPTRIGGER}" \
--scale out $VMSSAUTOSCALEROUTINCREASE
echo Enabling virtual machine autoscaler for scaling in
az monitor autoscale rule create \
--resource-group $RESOURCEGROUPNAME \
--autoscale-name $VMSSAUTOSCALERNAME \
--condition "${VMSSAUTOSCALERCRITERIA} < ${VMSSAUTOSCALERDOWNTRIGGER}" \
--scale in $VMSSAUTOSCALERINDECREASE