확장 가능한 엔터프라이즈 웹 라우팅: Azure App Gateway + VMSS와 Azure CLI
Source: Dev.to
위에 제공된 내용 외에 번역할 텍스트가 포함되어 있지 않습니다. 번역을 원하는 본문을 제공해 주시면 한국어로 번역해 드리겠습니다.
단일 서버만으로는 회복력 있는 웹 아키텍처를 구축할 수 없습니다
이 튜토리얼에서는 단순한 로드 밸런싱에서 Layer 7 Application Routing으로 전환합니다. Azure CLI를 사용하여 **Virtual Machine Scale Set (VMSS)**을 배포하고, 이를 Azure Application Gateway로 앞에 배치합니다.
🏗️ 아키텍처
표준 로드 밸런서(Layer 4)와 달리 **Application Gateway (Layer 7)**는 HTTP 헤더와 URL 경로를 기반으로 라우팅 결정을 내릴 수 있습니다. 우리는 이를 VMSS와 결합하여 백엔드가 수요에 따라 자동으로 확장되도록 합니다.
🛠️ 목표
- Application Gateway 배포 고급 웹 트래픽 관리를 위해.
- Azure CLI 숙달 인프라 자동화를 위해.
- VMSS Extensions 활용 자동으로 애플리케이션을 “bootstrap”하기 위해.
- Mock Service 설정 Python을 사용하여 격리된 네트워크 테스트를 위해.
💻 전체 자동화 스크립트
Copy and save this script as deploy_appgw.sh. If you are on Windows, you can run it in WSL or Azure Cloud Shell.
#!/bin/bash
# --- 1. Configuration ---
rg="my-automated-rg3"
location="eastus2"
vnet_name="shared-vnet"
vmss_name="Hub-VMSS"
appgw_name="Hub-AppGateway"
echo "--- Starting Phase 6: Application Gateway & VMSS Deployment ---"
# --- 2. Create the Dedicated App Gateway Subnet ---
# App Gateway v2 requires its own empty subnet (min /24 recommended)
echo "Adding Application Gateway Subnet..."
az network vnet subnet create \
--resource-group $rg \
--vnet-name $vnet_name \
--name appgw-subnet \
--address-prefixes 10.0.4.0/24
# --- 3. Deploy the Virtual Machine Scale Set (VMSS) ---
echo "Deploying VMSS (The Elastic Backend)..."
az vmss create \
--resource-group $rg \
--name $vmss_name \
--image Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest \
--vm-sku Standard_B2ts_v2 \
--instance-count 2 \
--vnet-name $vnet_name \
--subnet workload-subnet \
--upgrade-policy-mode automatic \
--admin-username azureuser \
--generate-ssh-keys
# --- 4. Automate App Deployment with VMSS Extensions ---
# This "bootstraps" a Python mock service on every instance as it scales
echo "Applying Custom Script Extension..."
az vmss extension set \
--publisher Microsoft.Azure.Extensions \
--version 2.0 \
--name CustomScript \
--resource-group $rg \
--vmss-name $vmss_name \
--settings '{"commandToExecute": "mkdir -p /tmp/www && echo \"
Backend Instance: $(hostname)
” > /tmp/www/index.html && cd /tmp/www && nohup python3 -m http.server 80 &”}’
--- 5. Deploy the Application Gateway ---
echo “Creating Public IP for Gateway…”
az network public-ip create
—resource-group $rg
—name appgw-public-ip
—allocation-method Static
—sku Standard
echo “Deploying Application Gateway (Standard_v2)…”
az network application-gateway create
—name $appgw_name
—resource-group $rg
—location $location
—capacity 2
—sku Standard_v2
—public-ip-address appgw-public-ip
—vnet-name $vnet_name
—subnet appgw-subnet
—frontend-port 80
—priority 100
—http-settings-port 80
—http-settings-protocol Http
--- 6. Connect VMSS to the Gateway Backend Pool ---
echo “Linking VMSS to Application Gateway…”
backend_pool_id=$(az network application-gateway address-pool show
—gateway-name $appgw_name
—resource-group $rg
—name appGatewayBackendPool
—query id -o tsv)
az vmss update
—resource-group $rg
—name $vmss_name
—set virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].applicationGatewayBackendAddressPools=”[{‘id’: ‘$backend_pool_id’}]“
Force update existing instances
az vmss update-instances —instance-ids ”*” —name $vmss_name —resource-group $rg
echo ”--- DEPLOYMENT COMPLETE ---“
## 🔍 배포 후 검사 (Azure CLI)
CLI는 실시간 리소스를 검사하는 가장 강력한 도구입니다. 이 명령을 사용하여 설정을 확인하십시오.
### 백엔드 상태 확인
Application Gateway가 VMSS 인스턴스를 성공적으로 “보고” 및 “프로브”할 수 있는지 확인합니다:
```bash
az network application-gateway show-backend-health \
--name Hub-AppGateway \
--resource-group my-automated-rg3
스케일 업!
인스턴스 수를 늘려 설계의 탄력성을 테스트합니다:
az vmss scale \
--resource-group my-automated-rg3 \
--name Hub-VMSS \
--new-capacity 4
❓ 문제 해결 팁
-
서브넷 제한
Application Gateway v2 반드시 자체 서브넷에 있어야 합니다.appgw-subnet에 VM이나 다른 리소스를 배치할 수 없습니다. 배포가 “Subnet Busy” 오류와 함께 실패하면 기존 NIC가 있는지 확인하세요. -
확장 문제
웹 서비스가 응답하지 않을 경우, VMSS 확장의 상태를 확인하세요:az vmss extension show \ --resource-group my-automated-rg3 \ --vmss-name Hub-VMSS \ --name CustomScript -
앱 게이트웨이 vs. 로드 밸런서: 어느 것을 선택할까?
- 로드 밸런서 (L4) – 내부 서비스(예: SQL, 비 HTTP 프로토콜)용 고성능, 저지연 트래픽에 사용합니다.
- 애플리케이션 게이트웨이 (L7) – SSL 종료, URL‑경로 라우팅, 또는 웹 애플리케이션 방화벽(WAF) 보호가 필요할 때 사용합니다.
🏁 결론
Application Gateway와 VMSS를 결합함으로써 Azure 네트워크를 위한 프로덕션‑레디 진입점을 구축했습니다. CLI 자동화와 확장 기능을 사용하면 환경을 반복 가능하고 손쉽게 확장할 수 있습니다.
