다음을 통해 공유


Aspire Azure 배포 설정 사용자 정의

(Azure Developer CLI)는 azd 애플리케이션에 대한 Aspire 기본 인프라 코드를 생성하고 사용자 지정할 수 있는 인프라 생성이라는 강력한 기능을 제공합니다. 이 기능은 리소스, 보안 구성 및 배포 패턴에 대한 Azure 세분화된 제어가 필요한 프로덕션 시나리오에 필수적입니다.

이 문서에서는 다음을 사용하는 azd infra gen 방법을 설명합니다.

  • 앱 모델Aspire에서 Bicep 인프라 파일을 생성합니다.
  • 프로덕션 요구 사항에 맞게 생성된 인프라를 사용자 지정합니다.
  • 생성된 리소스에 보안 모범 사례를 적용합니다.
  • 적절한 버전 제어를 사용하여 코드로 인프라를 관리합니다.

필수 조건

Aspire 작업을 수행하려면 다음을 로컬에 설치해야 합니다.

자세한 내용은 설정 및 도구 및 SDK를 참조Aspire하세요.Aspire

또한 로컬로 Azure Developer CLI설치해야 합니다.

인프라 생성 작동 방식

azd 인프라 생성에서는 Bicep 템플릿을 사용하여 Aspire 앱 모델을 구체적인 Azure 인프라 정의로 변환합니다. 이 프로세스는 개발 시점 오케스트레이션 Aspire 과 필요한 프로덕션 인프라 Azure 간의 격차를 해소합니다.

azd infra gen을 실행할 때, CLI는 다음을 수행합니다.

  1. AppHost 프로젝트를 분석합니다. Aspire
  2. 모든 리소스 및 해당 종속성을 식별합니다.
  3. Bicep에서 해당 Azure 리소스 정의를 생성합니다.
  4. 배포를 위한 지원 구성 파일을 만듭니다.

인프라 생성 활용

솔루션에서 인프라 생성 명령을 호출합니다 Aspire .

azd infra gen

이 명령은 다음 구조를 사용하여 infra AppHost 프로젝트 디렉터리에 폴더를 만듭니다.

└───📂 infra
     ├─── abbreviations.json   # Azure resource naming conventions  
     ├─── main.bicep           # Main infrastructure entry point
     ├─── main.parameters.json # Parameter values for deployment
     └─── resources.bicep      # Resource definitions    

프로덕션 고려 사항

생성된 인프라는 배포를 위한 견고한 기반을 제공하지만 프로덕션 환경에는 보안, 확장성 및 유지 관리를 위한 추가 구성이 필요합니다. 이 섹션에서는 프로덕션 배포를 준비할 때 사용자 지정해야 하는 주요 영역에 대해 설명합니다.

보안 구성

프로덕션 배포를 준비할 때 적절한 보안 제어를 사용하여 생성된 인프라를 검토하고 향상시킵니다.

네트워크 격리:

// Example: Configure Container Apps Environment with network restrictions
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
  name: environmentName
  location: location
  properties: {
    vnetConfiguration: {
      infrastructureSubnetId: subnetId
      internal: true
    }
    workloadProfiles: [
      {
        name: 'Consumption'
        workloadProfileType: 'Consumption'
      }
    ]
  }
}

ID 및 액세스 관리:

// Example: Configure managed identity with least privilege access
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
  name: identityName
  location: location
}

// Assign specific roles rather than broad permissions
resource acrPullRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
  scope: containerRegistry
  name: guid(containerRegistry.id, managedIdentity.id, 'AcrPull')
  properties: {
    roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') // AcrPull
    principalId: managedIdentity.properties.principalId
    principalType: 'ServicePrincipal'
  }
}

리소스 크기 설정 및 스케일링

프로덕션 요구 사항에 대해 생성된 리소스 구성을 검토합니다.

// Example: Configure appropriate resource limits
resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
  name: appName
  location: location
  properties: {
    configuration: {
      ingress: {
        external: true
        targetPort: 8080
        allowInsecure: false // Ensure HTTPS only
      }
    }
    template: {
      containers: [
        {
          name: containerName
          image: image
          resources: {
            cpu: json('1.0')      // Adjust based on load requirements
            memory: '2.0Gi'       // Adjust based on memory needs
          }
        }
      ]
      scale: {
        minReplicas: 2          // Ensure availability
        maxReplicas: 10         // Control costs
        rules: [
          {
            name: 'http-requests'
            http: {
              metadata: {
                concurrentRequests: '100'
              }
            }
          }
        ]
      }
    }
  }
}

환경별 구성

매개 변수를 사용하여 환경별 설정을 관리합니다.

@description('Environment name (dev, staging, prod)')
param environmentType string = 'dev'

@description('Application tier configuration')
var tierConfigurations = {
  dev: {
    skuName: 'Consumption'
    replicas: 1
  }
  staging: {
    skuName: 'Dedicated'
    replicas: 2
  }
  prod: {
    skuName: 'Dedicated'
    replicas: 3
  }
}

var currentTier = tierConfigurations[environmentType]

반복적인 사용자 지정 워크플로

초기 인프라를 생성한 후 지속적인 사용자 지정을 위한 워크플로를 설정합니다.

  1. 생성된 Bicep 파일에 인프라 변경을 적용합니다.
  2. 개발 환경에서 배포를 테스트합니다.
  3. 버전 관리로 인프라 변경 사항을 관리하십시오.
  4. 팀 공동 작업을 위한 문서 사용자 지정

중요합니다

다시 실행 azd infra gen 하면 파일이 다시 생성되고 사용자 지정을 덮어쓸 수 있습니다. 항상 버전 관리를 통해 변경 사항을 제어하고, 재구성 후 사용자 지정을 다시 적용할 준비를 합니다.

고급 사용자 지정 패턴

사용자 지정 리소스 정의

추가 Azure 리소스를 사용하여 생성된 인프라를 확장합니다.

// Add Application Insights for monitoring
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: '${resourceBaseName}-ai'
  location: location
  kind: 'web'
  properties: {
    Application_Type: 'web'
    Flow_Type: 'Redfield'
    Request_Source: 'IbizaWebAppExtensionCreate'
    WorkspaceResourceId: logAnalyticsWorkspace.id
  }
}

// Configure container apps to use Application Insights
resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
  // ... other properties
  properties: {
    template: {
      containers: [
        {
          // ... other container properties
          env: [
            {
              name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
              value: applicationInsights.properties.ConnectionString
            }
          ]
        }
      ]
    }
  }
}

인프라 유효성 검사

유효성 검사 규칙을 추가하여 적절한 리소스 구성을 확인합니다.

@description('Validates that environment type is supported')
@allowed(['dev', 'staging', 'prod'])
param environmentType string

@description('Validates location is in allowed regions')
@allowed(['eastus', 'westus2', 'northeurope'])
param location string

모범 사례

  • 버전 제어: 항상 생성된 인프라 파일을 소스 제어에 커밋합니다.
  • 환경 분리: 다른 환경에 대해 별도의 리소스 그룹 및 명명 규칙을 사용합니다.
  • 보안 검사: Bicep 템플릿의 자동화된 보안 검사를 구현합니다.
  • 비용 모니터링: 비용 추적을 위해 예산 경고 및 리소스 태그를 설정합니다.
  • 설명서: 사용자 지정 및 해당 근거에 대한 설명서를 유지 관리합니다.

다음 단계