Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
De Azure Developer CLI (azd) biedt een krachtige functie genaamd infrastructuurgeneratie waarmee u de onderliggende infrastructuurcode voor uw Aspire toepassingen kunt genereren en aanpassen. Deze mogelijkheid is essentieel voor productiescenario's waarbij u gedetailleerde controle nodig hebt over Azure resources, beveiligingsconfiguraties en implementatiepatronen.
In dit artikel wordt beschreven hoe u het volgende kunt gebruiken azd infra gen :
- Bicep-infrastructuurbestanden genereren op basis van uw Aspire app-model.
- Pas de gegenereerde infrastructuur aan voor productievereisten.
- Pas aanbevolen beveiligingsprocedures toe op gegenereerde resources.
- Infrastructuur beheren als code met het juiste versiebeheer.
Vereiste voorwaarden
Om met Aspire te werken, moet u het volgende lokaal geïnstalleerd hebben:
-
.NET 8,0 of .NET 9,0.
- Aspire Vanaf 9.4 .NET wordt 10 Preview 5 of hoger ondersteund.
- Een OCI-compatibele containerruntime, zoals:
- Docker Desktop of Podman. Voor meer informatie, zie Container runtime.
- Een IDE (Integrated Developer Environment) of code-editor, zoals:
- Visual Studio 2022 versie 17.9 of hoger (optioneel)
-
Visual Studio Code (optioneel)
- C# Dev Kit: extensie- (optioneel)
- JetBrains Rider met Aspire plugin (optioneel)
Zie setup en hulpprogramma's en SDK voor meer informatieAspire.Aspire
U moet de Azure Developer CLIinstallatie ook lokaal uitvoeren.
Hoe infrastructuur genereren werkt
Het genereren van infrastructuur in azd transformeert uw Aspire app-model in concrete Azure infrastructuurdefinities met behulp van Bicep-sjablonen. Dit proces overbrugt de kloof tussen de ontwikkelingstijdindeling in Aspire en de productie-infrastructuur die nodig is in Azure.
Wanneer u azd infra gen uitvoert, gebruikt u de CLI:
- Analyseert uw Aspire AppHost-project.
- Identificeert alle resources en de bijbehorende afhankelijkheden.
- Hiermee worden bijbehorende Azure resourcedefinities in Bicep gegenereerd.
- Hiermee maakt u ondersteunende configuratiebestanden voor implementatie.
Infrastructuurgeneratie gebruiken
Roep de opdracht Infrastructuur genereren aan voor uw Aspire oplossing:
azd infra gen
Met deze opdracht maakt u een infra map in uw AppHost-projectmap met de volgende structuur:
└───📂 infra
├─── abbreviations.json # Azure resource naming conventions
├─── main.bicep # Main infrastructure entry point
├─── main.parameters.json # Parameter values for deployment
└─── resources.bicep # Resource definitions
Overwegingen voor productie
De gegenereerde infrastructuur biedt een solide basis voor uw implementatie, maar voor productieomgevingen is extra configuratie vereist voor beveiliging, schaalbaarheid en onderhoud. In deze sectie worden de belangrijkste gebieden besproken die u moet aanpassen bij het voorbereiden van de productie-implementatie.
Beveiligingsconfiguraties
Wanneer u zich voorbereidt op productie-implementaties, controleert en verbetert u de gegenereerde infrastructuur met de juiste beveiligingscontroles:
Netwerkisolatie:
// 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'
}
]
}
}
Identiteits- en toegangsbeheer:
// 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'
}
}
Groottebepaling en schalen van middelen
Bekijk gegenereerde resourceconfiguraties voor productievereisten:
// 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'
}
}
}
]
}
}
}
}
Omgevingsspecifieke configuraties
Parameters gebruiken om omgevingsspecifieke instellingen te beheren:
@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]
Werkstroom voor iteratieve aanpassing
Na het genereren van de eerste infrastructuur maakt u een werkstroom voor doorlopende aanpassing:
- Breng infrastructuurwijzigingen aan in de gegenereerde Bicep-bestanden.
- Test implementaties in ontwikkelomgevingen.
- Versiebeheer voor uw infrastructuurwijzigingen.
- Documentaanpassingen voor teamsamenwerking.
Belangrijk
Als u azd infra gen opnieuw uitvoert, worden de bestanden opnieuw gegenereerd en worden uw aanpassingen overschreven. Zorg ervoor dat u altijd uw wijzigingen versiebeheert en wees voorbereid om aanpassingen na regeneratie opnieuw door te voeren.
Geavanceerde aanpassingspatronen
Aangepaste hulpbronnen definities
Gegenereerde infrastructuur uitbreiden met aanvullende Azure middelen:
// 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
}
]
}
]
}
}
}
Infrastructuurvalidatie
Voeg validatieregels toe om de juiste resourceconfiguratie te garanderen:
@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
Beste praktijken
- Versiebeheer: voer altijd gegenereerde infrastructuurbestanden door naar broncodebeheer.
- Omgevingsscheiding: gebruik afzonderlijke resourcegroepen en naamconventies voor verschillende omgevingen.
- Beveiligingsscans: Geautomatiseerde beveiligingsscans van Bicep-sjablonen implementeren.
- Kostenbewaking: budgetwaarschuwingen en resourcetags instellen voor het bijhouden van kosten.
- Documentatie: Documentatie over aanpassingen en hun logica behouden.