TL;DR
Learn how to deploy and manage web applications using Azure App Service. Covers deployment slots, scaling, monitoring, and continuous deployment.
Deploying Applications with Azure App Service
Azure App Service is a fully managed platform for building, deploying, and scaling web applications. This guide covers everything you need to know about using Azure App Service effectively.
$1
$1
$1
`` az group create --name myResourceGroup --location eastus az appservice plan create \
--name myAppServicePlan \
--resource-group myResourceGroup \
--sku B1 \
--is-linux az webapp create \
--name myWebApp \
--resource-group myResourceGroup \
--plan myAppServicePlan \
--runtime "NODE|14-lts"
bash
`Create a resource group
Create an App Service plan
Create a web app
$1
` {
"appSettings": [
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "DATABASE_URL",
"value": "your-connection-string"
}
],
"connectionStrings": [
{
"name": "MyDatabase",
"type": "SQLAzure",
"value": "Server=tcp:..."
}
]
}
json
`
$1
$1
` az webapp deployment slot create \
--name myWebApp \
--resource-group myResourceGroup \
--slot staging az webapp deployment slot auto-swap \
--name myWebApp \
--resource-group myResourceGroup \
--slot staging
bash
`Create a deployment slot
Configure auto swap
$1
` {
"slotConfigNames": [
"CONNECTION_STRING",
"API_KEY"
],
"stickySettings": {
"appSettingNames": [
"WEBSITE_NODE_DEFAULT_VERSION"
]
}
}
json
`
$1
$1
` {
"rules": [
{
"metricTrigger": {
"metricName": "CpuPercentage",
"metricResourceUri": "[resourceId('Microsoft.Web/serverfarms', 'myAppServicePlan')]",
"timeGrain": "PT1M",
"statistic": "Average",
"timeWindow": "PT10M",
"timeAggregation": "Average",
"operator": "GreaterThan",
"threshold": 70
},
"scaleAction": {
"direction": "Increase",
"type": "ChangeCount",
"value": "1",
"cooldown": "PT10M"
}
}
]
}
json
`
$1
$1
` az webapp config appsettings set \
--name myWebApp \
--resource-group myResourceGroup \
--settings APPINSIGHTS_INSTRUMENTATIONKEY=your-key az monitor diagnostic-settings create \
--name myDiagnostics \
--resource myWebApp \
--logs "[{category: 'AppServiceHTTPLogs', enabled: true}]" \
--metrics "[{category: 'AllMetrics', enabled: true}]"
bash
`Enable Application Insights
Configure diagnostic settings
$1
1. Network Security
- Enable App Service Authentication
- Use Virtual Network Integration
- Configure IP restrictions
2. SSL/TLS Configuration
- Enable HTTPS Only
- Use TLS 1.2 or higher
- Implement HSTS
3. Access Control
- Implement RBAC
- Use Managed Identities
- Regular key rotation
$1
$1
` {
"caching": {
"profiles": [
{
"name": "Default",
"duration": "23:00:00",
"location": "Any"
}
],
"rules": [
{
"path": "/*",
"profile": "Default"
}
]
}
}
json
`
$1
$1
` name: Deploy to Azure App Service on:
push:
branches: [ main ] jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to Azure
uses: azure/webapps-deploy@v2
with:
app-name: 'myWebApp'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: .
yaml
`
$1
1. Deployment Failures
- Check deployment logs
- Verify dependencies
- Validate configuration settings
2. Performance Issues
- Monitor resource utilization
- Check application logs
- Analyze slow requests
3. Connectivity Problems
- Verify network configuration
- Check SSL/TLS settings
- Validate connection strings
$1
$1
` az webapp update \
--name myWebApp \
--resource-group myResourceGroup \
--set numberOfWorkers=1 az webapp config set \
--name myWebApp \
--resource-group myResourceGroup \
--generic-configurations "{'autoShutdownEnabled': true, 'autoShutdownTime': '2200'}"
bash
``Scale down during off-hours
Enable auto-shutdown
$1
Azure App Service provides a robust platform for hosting web applications with enterprise-grade features. By following this guide's best practices for deployment, security, and management, you can build and maintain scalable web applications efficiently.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.