SKU选择指南 - 如何选择合适的Azure服务层级 章节导航: 课程主页:AZD入门教程 当前章节:第6章 - 部署前验证与规划 ⬅️ 上一章:容量规划 ➡️ 下一章:预检查 下一章节:第7章:故障排查 简介 本指南将帮助您为不同环境、工作负载和需求选择最佳的Azure服务SKU(库存单位)。通过学习分析性能需求、成本考虑和可扩展性要求,您将能够为Azure Developer CLI部署选择最合适的服务层级。
章节导航:
本指南将帮助您为不同环境、工作负载和需求选择最佳的Azure服务SKU(库存单位)。通过学习分析性能需求、成本考虑和可扩展性要求,您将能够为Azure Developer CLI部署选择最合适的服务层级。
完成本指南后,您将能够:
完成后,您将能够:
SKU(库存单位)代表Azure资源的不同服务层级和性能水平。每个SKU提供不同的:
工作负载需求
环境类型
预算限制
增长预测
优先级:成本优化、基本功能、易于配置和删除
# Development environment configuration environment: development skus: app_service: "F1" # Free tier sql_database: "Basic" # Basic tier, 5 DTU storage: "Standard_LRS" # Locally redundant cosmos_db: "Free" # Free tier (400 RU/s) key_vault: "Standard" # Standard pricing tier application_insights: "Free" # First 5GB free
优先级:接近生产配置、成本平衡、性能测试能力
# Staging environment configuration environment: staging skus: app_service: "S1" # Standard tier sql_database: "S2" # Standard tier, 50 DTU storage: "Standard_GRS" # Geo-redundant cosmos_db: "Standard" # 400 RU/s provisioned container_apps: "Consumption" # Pay-per-use
优先级:性能、可用性、安全性、合规性、可扩展性
# Production environment configuration environment: production skus: app_service: "P1V3" # Premium v3 tier sql_database: "P2" # Premium tier, 250 DTU storage: "Premium_GRS" # Premium geo-redundant cosmos_db: "Provisioned" # Dedicated throughput container_apps: "Dedicated" # Dedicated environment key_vault: "Premium" # Premium with HSM
| 使用场景 | 推荐SKU | 理由 |
|---|---|---|
| 开发/测试 | F1(免费)或B1(基础) | 成本低,足够测试 |
| 小型生产应用 | S1(标准) | 自定义域名、SSL、自动扩展 |
| 中型生产应用 | P1V3(高级V3) | 更好的性能,更多功能 |
| 高流量应用 | P2V3或P3V3 | 专用资源,高性能 |
| 关键任务应用 | I1V2(隔离V2) | 网络隔离,专用硬件 |
开发
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = { name: 'asp-${environmentName}-dev' location: location sku: { name: 'F1' tier: 'Free' capacity: 1 } properties: { reserved: false } }
生产
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = { name: 'asp-${environmentName}-prod' location: location sku: { name: 'P1V3' tier: 'PremiumV3' capacity: 3 } properties: { reserved: false } }
基于DTU(数据库事务单位)
基于vCore(推荐用于生产)
// Development resource sqlDatabase 'Microsoft.Sql/servers/databases@2022-05-01-preview' = { name: 'db-${environmentName}-dev' parent: sqlServer location: location sku: { name: 'Basic' tier: 'Basic' capacity: 5 } properties: { maxSizeBytes: 2147483648 // 2GB } } // Production resource sqlDatabase 'Microsoft.Sql/servers/databases@2022-05-01-preview' = { name: 'db-${environmentName}-prod' parent: sqlServer location: location sku: { name: 'GP_Gen5' tier: 'GeneralPurpose' family: 'Gen5' capacity: 4 } properties: { maxSizeBytes: 536870912000 // 500GB } }
基于使用量
专用(工作负载配置文件)
开发(基于使用量)
resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2022-10-01' = { name: 'cae-${environmentName}-dev' location: location properties: { zoneRedundant: false } } resource containerApp 'Microsoft.App/containerApps@2022-10-01' = { name: 'ca-${environmentName}-dev' location: location properties: { managedEnvironmentId: containerAppEnvironment.id configuration: { ingress: { external: true targetPort: 3000 } } template: { containers: [{ name: 'main' image: 'nginx:latest' resources: { cpu: json('0.25') memory: '0.5Gi' } }] scale: { minReplicas: 0 maxReplicas: 1 } } } }
生产(专用)
resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2022-10-01' = { name: 'cae-${environmentName}-prod' location: location properties: { zoneRedundant: true workloadProfiles: [{ name: 'production-profile' workloadProfileType: 'D4' minimumCount: 2 maximumCount: 10 }] } }
手动预配吞吐量
自动扩展预配吞吐量
无服务器
// Development - Serverless resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = { name: 'cosmos-${environmentName}-dev' location: location properties: { databaseAccountOfferType: 'Standard' locations: [{ locationName: location }] capabilities: [{ name: 'EnableServerless' }] } } // Production - Provisioned with Autoscale resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = { name: 'cosmos-${environmentName}-prod' location: location properties: { databaseAccountOfferType: 'Standard' locations: [ { locationName: location failoverPriority: 0 } { locationName: secondaryLocation failoverPriority: 1 } ] enableAutomaticFailover: true enableMultipleWriteLocations: false } } resource cosmosDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2023-04-15' = { name: 'main' parent: cosmosAccount properties: { resource: { id: 'main' } options: { autoscaleSettings: { maxThroughput: 4000 } } } }
// Development resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = { name: 'sa${uniqueString(resourceGroup().id)}dev' location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' properties: { accessTier: 'Hot' allowBlobPublicAccess: false minimumTlsVersion: 'TLS1_2' } } // Production resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = { name: 'sa${uniqueString(resourceGroup().id)}prod' location: location sku: { name: 'Standard_GRS' } kind: 'StorageV2' properties: { accessTier: 'Hot' allowBlobPublicAccess: false minimumTlsVersion: 'TLS1_2' networkAcls: { defaultAction: 'Deny' virtualNetworkRules: [] ipRules: [] } } }
预留1-3年的资源以获得显著折扣:
# Check reservation options az reservations catalog show --reserved-resource-type SqlDatabase az reservations catalog show --reserved-resource-type CosmosDb
从较小的SKU开始,根据实际使用情况扩展:
# Progressive scaling approach development: app_service: "F1" # Free tier testing: app_service: "B1" # Basic tier staging: app_service: "S1" # Standard tier production: app_service: "P1V3" # Premium tier
实施智能扩展以优化成本:
resource autoScaleSettings 'Microsoft.Insights/autoscalesettings@2022-10-01' = { name: 'autoscale-${appServicePlan.name}' location: location properties: { profiles: [{ name: 'default' capacity: { minimum: '1' maximum: '10' default: '2' } rules: [ { metricTrigger: { metricName: 'CpuPercentage' metricResourceUri: appServicePlan.id operator: 'GreaterThan' threshold: 70 timeAggregation: 'Average' timeGrain: 'PT1M' timeWindow: 'PT5M' } scaleAction: { direction: 'Increase' type: 'ChangeCount' value: '1' cooldown: 'PT5M' } } { metricTrigger: { metricName: 'CpuPercentage' metricResourceUri: appServicePlan.id operator: 'LessThan' threshold: 30 timeAggregation: 'Average' timeGrain: 'PT1M' timeWindow: 'PT5M' } scaleAction: { direction: 'Decrease' type: 'ChangeCount' value: '1' cooldown: 'PT5M' } } ] }] enabled: true targetResourceUri: appServicePlan.id } }
在非工作时间缩减规模:
{ "profiles": [ { "name": "business-hours", "capacity": { "minimum": "2", "maximum": "10", "default": "3" }, "recurrence": { "frequency": "Week", "schedule": { "timeZone": "Pacific Standard Time", "days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "hours": [8], "minutes": [0] } } }, { "name": "off-hours", "capacity": { "minimum": "1", "maximum": "2", "default": "1" }, "recurrence": { "frequency": "Week", "schedule": { "timeZone": "Pacific Standard Time", "days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "hours": [18], "minutes": [0] } } } ] }
在选择SKU之前定义明确的性能需求:
performance_requirements: response_time: p95: "< 500ms" p99: "< 1000ms" throughput: requests_per_second: 1000 concurrent_users: 500 availability: uptime: "99.9%" rpo: "15 minutes" rto: "30 minutes"
测试不同SKU以验证性能:
# Azure Load Testing service az load test create \ --name "sku-performance-test" \ --resource-group $RESOURCE_GROUP \ --load-test-config @load-test-config.yaml
设置全面的监控:
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = { name: 'ai-${environmentName}' location: location kind: 'web' properties: { Application_Type: 'web' RetentionInDays: 90 } } resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = { name: 'law-${environmentName}' location: location properties: { sku: { name: 'PerGB2018' } retentionInDays: 30 } }
| SKU | 层级 | vCPU | RAM | 存储 | 价格范围 | 使用场景 |
|---|---|---|---|---|---|---|
| F1 | 免费 | 共享 | 1GB | 1GB | 免费 | 开发 |
| B1 | 基础 | 1 | 1.75GB | 10GB | $ | 小型应用 |
| S1 | 标准 | 1 | 1.75GB | 50GB | $$ | 生产 |
| P1V3 | 高级V3 | 2 | 8GB | 250GB | $ | 高性能 |
| I1V2 | 隔离V2 | 2 | 8GB | 1TB | $$ | 企业级 |
| SKU | 层级 | DTU/vCore | 存储 | 价格范围 | 使用场景 |
|---|---|---|---|---|---|
| 基础 | 基础 | 5 DTU | 2GB | $ | 开发 |
| S2 | 标准 | 50 DTU | 250GB | $$ | 小型生产 |
| P2 | 高级 | 250 DTU | 1TB | $ | 高性能 |
| GP_Gen5_4 | 通用用途 | 4 vCore | 4TB | $ | 平衡型 |
| BC_Gen5_8 | 业务关键 | 8 vCore | 4TB | $$ | 关键任务 |
| 模型 | 定价 | CPU/内存 | 使用场景 |
|---|---|---|---|
| 基于使用量 | 按使用付费 | 0.25-2 vCPU | 开发,可变负载 |
| 专用D4 | 预留 | 4 vCPU, 16GB | 生产 |
| 专用D8 | 预留 | 8 vCPU, 32GB | 高性能 |
#!/bin/bash # Check SKU availability in target region check_sku_availability() { local region=$1 local resource_type=$2 local sku=$3 echo "Checking $sku availability for $resource_type in $region..." case $resource_type in "app-service") az appservice list-locations --sku $sku --output table ;; "sql-database") az sql db list-editions --location $region --output table ;; "storage") az storage account check-name --name "test" --output table ;; *) echo "Resource type not supported" ;; esac } # Usage check_sku_availability "eastus" "app-service" "P1V3"
# PowerShell script for cost estimation function Get-AzureCostEstimate { param( [string]$SubscriptionId, [string]$ResourceGroup, [hashtable]$Resources ) $totalCost = 0 foreach ($resource in $Resources.GetEnumerator()) { $resourceType = $resource.Key $sku = $resource.Value # Use Azure Pricing API or calculator $cost = Get-ResourceCost -Type $resourceType -SKU $sku $totalCost += $cost Write-Host "$resourceType ($sku): $cost/month" } Write-Host "Total estimated cost: $totalCost/month" } # Usage $resources = @{ "AppService" = "P1V3" "SqlDatabase" = "GP_Gen5_4" "StorageAccount" = "Standard_GRS" } Get-AzureCostEstimate -ResourceGroup "rg-myapp-prod" -Resources $resources
# Load test configuration for SKU validation test_configuration: duration: "10m" users: spawn_rate: 10 max_users: 100 scenarios: - name: "sku_performance_test" requests: - url: "https://myapp.azurewebsites.net/api/health" method: "GET" expect: - status_code: 200 - response_time_ms: 500 - url: "https://myapp.azurewebsites.net/api/data" method: "POST" expect: - status_code: 201 - response_time_ms: 1000 thresholds: http_req_duration: - "p(95)<500" # 95% of requests under 500ms - "p(99)<1000" # 99% of requests under 1s http_req_failed: - "rate<0.1" # Less than 10% failure rate
专业提示:使用Azure成本管理和顾问工具,根据实际使用模式获取个性化的SKU优化建议。
导航
免责声明:
本文档使用AI翻译服务Co-op Translator进行翻译。尽管我们努力确保翻译的准确性,但请注意,自动翻译可能包含错误或不准确之处。原始语言的文档应被视为权威来源。对于关键信息,建议使用专业人工翻译。我们不对因使用此翻译而产生的任何误解或误读承担责任。