ASP.NET Core Deployment Guide
Provides comprehensive deployment guides for ASP.NET Core applications to Azure App Service, Docker, and Kubernetes.
/plugin marketplace add pluginagentmarketplace/custom-plugin-aspnet-core/plugin install custom-plugin-aspnet-core@pluginagentmarketplace-aspnet-coreDeploy your ASP.NET Core application to production.
# Create Resource Group
az group create --name myResourceGroup --location eastus
# Create App Service Plan
az appservice plan create \
--name myAppServicePlan \
--resource-group myResourceGroup \
--sku B1 \
--is-linux
# Create Web App
az webapp create \
--resource-group myResourceGroup \
--plan myAppServicePlan \
--name myapp-<unique-suffix> \
--runtime "DOTNET:8.0"
# Publish application
dotnet publish -c Release -o ./publish
# Create deployment package
cd publish
zip -r ../app.zip .
cd ..
# Deploy to App Service
az webapp deployment source config-zip \
--resource-group myResourceGroup \
--name myapp-<unique-suffix> \
--src app.zip
# Verify deployment
az webapp show \
--resource-group myResourceGroup \
--name myapp-<unique-suffix>
# Create Azure SQL Database
az sql server create \
--resource-group myResourceGroup \
--name myserver \
--admin-user sqladmin \
--admin-password P@ssw0rd
# Create database
az sql db create \
--resource-group myResourceGroup \
--server myserver \
--name myappdb
# Get connection string
az sql db show-connection-string \
--client ado.net \
--server myserver \
--name myappdb
# Add connection string to App Service
az webapp config appsettings set \
--resource-group myResourceGroup \
--name myapp-<unique-suffix> \
--settings ConnectionStrings__DefaultConnection="<connection-string>"
# Setup application settings
az webapp config appsettings set \
--resource-group myResourceGroup \
--name myapp-<unique-suffix> \
--settings ASPNETCORE_ENVIRONMENT=Production
docker build -t myapp:1.0 .
docker tag myapp:1.0 myregistry.azurecr.io/myapp:1.0
# Create registry
az acr create \
--resource-group myResourceGroup \
--name myregistry \
--sku Basic
# Login
az acr login --name myregistry
# Push image
docker push myregistry.azurecr.io/myapp:1.0
az container create \
--resource-group myResourceGroup \
--name myapp-container \
--image myregistry.azurecr.io/myapp:1.0 \
--registry-login-server myregistry.azurecr.io \
--registry-username <username> \
--registry-password <password> \
--environment-variables ASPNETCORE_ENVIRONMENT=Production \
--ports 80 443 \
--protocol TCP
az aks create \
--resource-group myResourceGroup \
--name myAKSCluster \
--node-count 3 \
--vm-set-type VirtualMachineScaleSets \
--network-plugin azure \
--service-cidr 10.0.0.0/16 \
--dns-service-ip 10.0.0.10
az aks get-credentials \
--resource-group myResourceGroup \
--name myAKSCluster
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myregistry.azurecr.io/myapp:1.0
ports:
- containerPort: 80
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Production"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 10
periodSeconds: 10
---
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
# Get load balancer IP
kubectl get service myapp-service
name: Deploy to Azure
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'
- name: Publish
run: dotnet publish -c Release -o ./publish
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: webapp
path: ./publish
- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: myapp-<unique-suffix>
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
package: ./publish
# Check application status
curl https://myapp-<unique-suffix>.azurewebsites.net/health
# Expected response: 200 OK
# Create Application Insights
az monitor app-insights component create \
--app myapp-insights \
--location eastus \
--resource-group myResourceGroup
# Link to App Service
az webapp config set \
--resource-group myResourceGroup \
--name myapp-<unique-suffix> \
--app-insights-key <instrumentation-key>
# Run migrations after deployment
dotnet ef database update --configuration Release
# View logs
az webapp log tail \
--resource-group myResourceGroup \
--name myapp-<unique-suffix>
# Check resource status
az webapp show \
--resource-group myResourceGroup \
--name myapp-<unique-suffix> \
--query state
# Restart application
az webapp restart \
--resource-group myResourceGroup \
--name myapp-<unique-suffix>