Azure
Deploying Applications with Azure App Service
Learn how to deploy and manage web applications using Azure App Service. Covers deployment slots, scaling, monitoring, and continuous deployment.
March 3, 2024
Technical Writer
4 min read
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.
Key Features of Azure App Service
- Multiple Language Support: .NET, Java, Node.js, Python, PHP
- Built-in CI/CD: Integration with GitHub, Azure DevOps, and other sources
- Auto-scaling: Horizontal and vertical scaling capabilities
- Deployment Slots: Zero-downtime deployments
- SSL/TLS Support: Managed certificates and custom domains
- Authentication: Built-in authentication and authorization
Getting Started
Creating an App Service
# Create a resource group az group create --name myResourceGroup --location eastus # Create an App Service plan az appservice plan create \ --name myAppServicePlan \ --resource-group myResourceGroup \ --sku B1 \ --is-linux # Create a web app az webapp create \ --name myWebApp \ --resource-group myResourceGroup \ --plan myAppServicePlan \ --runtime "NODE|14-lts"
Configuration Settings
{ "appSettings": [ { "name": "NODE_ENV", "value": "production" }, { "name": "DATABASE_URL", "value": "your-connection-string" } ], "connectionStrings": [ { "name": "MyDatabase", "type": "SQLAzure", "value": "Server=tcp:..." } ] }
Deployment Slots
Creating and Managing Slots
# Create a deployment slot az webapp deployment slot create \ --name myWebApp \ --resource-group myResourceGroup \ --slot staging # Configure auto swap az webapp deployment slot auto-swap \ --name myWebApp \ --resource-group myResourceGroup \ --slot staging
Slot Settings
{ "slotConfigNames": [ "CONNECTION_STRING", "API_KEY" ], "stickySettings": { "appSettingNames": [ "WEBSITE_NODE_DEFAULT_VERSION" ] } }
Auto-Scaling Configuration
Rules-Based Scaling
{ "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" } } ] }
Monitoring and Diagnostics
Application Insights Integration
# Enable Application Insights az webapp config appsettings set \ --name myWebApp \ --resource-group myResourceGroup \ --settings APPINSIGHTS_INSTRUMENTATIONKEY=your-key # Configure diagnostic settings az monitor diagnostic-settings create \ --name myDiagnostics \ --resource myWebApp \ --logs "[{category: 'AppServiceHTTPLogs', enabled: true}]" \ --metrics "[{category: 'AllMetrics', enabled: true}]"
Security Best Practices
-
Network Security
- Enable App Service Authentication
- Use Virtual Network Integration
- Configure IP restrictions
-
SSL/TLS Configuration
- Enable HTTPS Only
- Use TLS 1.2 or higher
- Implement HSTS
-
Access Control
- Implement RBAC
- Use Managed Identities
- Regular key rotation
Performance Optimization
Caching Configuration
{ "caching": { "profiles": [ { "name": "Default", "duration": "23:00:00", "location": "Any" } ], "rules": [ { "path": "/*", "profile": "Default" } ] } }
Continuous Deployment
GitHub Actions Workflow
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: .
Troubleshooting Common Issues
-
Deployment Failures
- Check deployment logs
- Verify dependencies
- Validate configuration settings
-
Performance Issues
- Monitor resource utilization
- Check application logs
- Analyze slow requests
-
Connectivity Problems
- Verify network configuration
- Check SSL/TLS settings
- Validate connection strings
Cost Management
Resource Optimization
# Scale down during off-hours az webapp update \ --name myWebApp \ --resource-group myResourceGroup \ --set numberOfWorkers=1 # Enable auto-shutdown az webapp config set \ --name myWebApp \ --resource-group myResourceGroup \ --generic-configurations "{'autoShutdownEnabled': true, 'autoShutdownTime': '2200'}"
Conclusion
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.
azure
app-service
web-apps
paas