Azure Container Apps
Lab Objective
In this hands-on lab, you will learn how to:
- Deploy Container Apps with serverless scaling and auto-scaling capabilities
- Configure microservices communication using service discovery and internal networking
- Implement traffic splitting for blue-green deployments and A/B testing
- Set up ingress and custom domains with SSL termination and external access
- Configure environment variables and secrets using managed identity and Key Vault integration
- Monitor applications with built-in observability tools and custom metrics
- Scale applications based on HTTP requests, CPU, memory, and custom metrics
Scenario: Your organization is modernizing applications using a microservices architecture. You need to deploy multiple interconnected services that can scale independently, communicate securely, and handle varying traffic loads. Azure Container Apps provides the serverless container platform perfect for this modern application architecture.
Please sign in to launch lab.
Pre-Provisioned Environment
Container Apps Lab Environmentβββ Resource Group: ContainerApps-Lab-RGβββ Container Apps Environment (ca-environment-lab)β βββ Virtual Network: Consumption plan with subnet delegationβ βββ Log Analytics Workspace: Integrated loggingβ βββ Application Insights: Performance monitoringβ βββ Managed Environment Certificate: Ready for custom domainsβββ Azure Container Registry (acrlab[unique])β βββ SKU: Basicβ βββ Admin User: Enabledβ βββ Sample Images: Pre-built demo applicationsβ βββ Managed Identity: Configured for Container Apps accessβββ Key Vault (kv-containerlab[unique])β βββ Managed Identity Access: Configuredβ βββ Sample Secrets: Database connection stringsβ βββ SSL Certificates: Ready for custom domain configurationβββ Azure Database for PostgreSQL (postgres-lab[unique])β βββ Tier: Burstableβ βββ Database: sampledbβ βββ Connection configured for Container Appsβββ Storage Account (storage[unique]) βββ Container: uploads βββ Blob access configured with managed identityImportant: The Container Apps Environment is ready with networking, monitoring, and security configured. Youβll focus on deploying applications, configuring scaling, and implementing microservices patterns.
Lab Exercises
Part 1: Deploy Your First Container App
Step 1: Explore Container Apps Environment
- Navigate to Resource Groups β
ContainerApps-Lab-RG - Click on Container Apps Environment
ca-environment-lab - Review the environment configuration:
- Networking configuration
- Log Analytics integration
- Custom domain settings
- Note the environment FQDN for later use
Step 2: Deploy a Simple Web Application
- Click βCreateβ in the Container Apps Environment
- Configure the basic container app:
- Name:
web-frontend - Container image:
mcr.microsoft.com/azuredocs/containerapps-helloworld:latest - Target port: 80
- Name:
- Configure ingress:
- Ingress: Enabled
- Ingress traffic: Accepting traffic from anywhere
- Target port: 80
- Click βCreateβ
Step 3: Test the Deployed Application
- Wait for deployment to complete
- Go to the
web-frontendcontainer app - Copy the Application URL from Overview
- Open the URL in a browser
- Verify the hello world application loads
- Note the container instance information displayed
Expected Results: A working web application is deployed and accessible via HTTPS with automatic SSL certificate provisioning.
Part 2: Configure Application Scaling and Resources
Step 1: Configure Auto-scaling Rules
- Go to
web-frontendcontainer app - Click βScale and replicasβ under Application
- Configure HTTP scaling:
- Min replicas: 1
- Max replicas: 10
- HTTP concurrent requests: 50
- Add CPU scaling rule:
- Scale rule name:
cpu-scaling - Type: CPU
- CPU Utilization: 70%
- Scale rule name:
- Save the configuration
Step 2: Configure Resource Allocation
- Go to βContainersβ under Application
- Edit the container configuration:
- CPU: 0.5 cores
- Memory: 1 GB
- Configure health probes:
- Liveness probe: HTTP GET on
/ - Readiness probe: HTTP GET on
/
- Liveness probe: HTTP GET on
- Save changes and wait for revision deployment
Step 3: Test Scaling Behavior
- Open Azure Cloud Shell
- Generate load to test scaling:
Terminal window # Replace with your app URL$appUrl = "https://web-frontend.xxx.azurecontainerapps.io"# Generate loadfor ($i = 1; $i -le 100; $i++) {Invoke-RestMethod -Uri $appUrl -Method GETStart-Sleep -Milliseconds 100} - Monitor scaling in the portal under βMetricsβ
- Observe new replicas being created
Expected Results: Container app automatically scales based on traffic and resource utilization with configurable scaling rules.
Part 3: Deploy Microservices Architecture
Step 1: Deploy API Backend Service
- Create a new container app:
api-backend - Configure the backend service:
- Container image:
mcr.microsoft.com/azuredocs/containerapps-helloworld:latest - Target port: 80
- Ingress: Internal only (for service-to-service communication)
- Container image:
- Configure environment variables:
- DATABASE_URL: Connection string to PostgreSQL
- STORAGE_ACCOUNT: Name of the storage account
- Deploy the backend service
Step 2: Configure Service Discovery
- Go to
web-frontendcontainer app - Edit the container configuration
- Add environment variable:
- API_BACKEND_URL:
http://api-backend
- API_BACKEND_URL:
- Save and redeploy
- Verify internal service communication works
Step 3: Deploy Data Processing Service
- Create container app:
data-processor - Configure as background service:
- Container image:
mcr.microsoft.com/azuredocs/containerapps-helloworld:latest - Ingress: Disabled (background processing)
- Min replicas: 1
- Max replicas: 5
- Container image:
- Configure CPU-based scaling for processing workloads
- Add managed identity for secure resource access
Expected Results: Multiple microservices deployed with internal communication and secure service discovery working between components.
Part 4: Implement Advanced Traffic Management
Step 1: Create Blue-Green Deployment
- Go to
web-frontendcontainer app - Create a new revision with updated configuration:
- Container image:
mcr.microsoft.com/azuredocs/containerapps-helloworld:latest - Environment variable:
VERSION=green
- Container image:
- Configure traffic splitting:
- Blue revision: 80% traffic
- Green revision: 20% traffic
- Save and monitor traffic distribution
Step 2: Test Traffic Splitting
- Visit the application URL multiple times
- Observe different versions being served
- Monitor performance metrics for both revisions
- Gradually shift traffic to the green revision
- Complete the deployment by routing 100% to green
Step 3: Configure Custom Domain
- Go to Container Apps Environment
- Click βCustom domainsβ
- Add a custom domain (you can use a test domain):
- Domain:
app.yourdomain.com - Certificate: Upload or use managed certificate
- Domain:
- Configure DNS records as instructed
- Bind the domain to your
web-frontendapp
Expected Results: Advanced traffic management with blue-green deployments and custom domain configuration working properly.
Part 5: Configure Security and Identity
Step 1: Enable Managed Identity
- Go to
api-backendcontainer app - Click βIdentityβ under Settings
- Enable system-assigned managed identity
- Copy the Principal ID for later use
Step 2: Configure Key Vault Integration
- Go to the Key Vault
kv-containerlab[unique] - Add access policy for the managed identity:
- Principal: Container app managed identity
- Secret permissions: Get, List
- Go back to
api-backendcontainer app - Add Key Vault reference:
- Name:
DATABASE_CONNECTION - Value: Key Vault secret reference
- Name:
Step 3: Configure Secure Storage Access
- Go to Storage Account
- Assign βStorage Blob Data Readerβ role to container app identity
- Update
data-processorapp:- Remove connection string environment variable
- Add managed identity authentication code
- Test secure access to storage without connection strings
Expected Results: Container apps authenticate securely using managed identity without storing credentials in configuration.
Part 6: Monitor and Troubleshoot Applications
Step 1: Configure Application Insights
- Go to Container Apps Environment
- Review Application Insights integration
- Navigate to Application Insights resource
- Explore application map showing service dependencies
- Review performance metrics and request telemetry
Step 2: Configure Custom Metrics and Alerts
- Go to
web-frontendcontainer app - Click βMetricsβ under Monitoring
- Create custom metric charts:
- HTTP requests per second
- Response time percentiles
- Active replicas
- Create alert rules:
- High response time alert
- Scaling event notifications
Step 3: Analyze Logs and Troubleshoot
- Go to βLogsβ under Monitoring
- Run queries to analyze application behavior:
ContainerAppConsoleLogs_CL| where ContainerAppName_s == "web-frontend"| where TimeGenerated > ago(1h)| order by TimeGenerated desc
- Create custom dashboard for monitoring
- Set up log-based alerts for error conditions
- Practice troubleshooting common container issues
Expected Results: Comprehensive monitoring and troubleshooting capabilities with custom dashboards and proactive alerting configured.
Troubleshooting Guide
Deployment Issues
- Container app wonβt start: Check container image availability and port configuration
- Ingress not working: Verify target port matches container listening port
- Environment issues: Check Container Apps Environment health and networking
- Resource constraints: Review CPU/memory limits and scaling configuration
Scaling Issues
- Apps not scaling: Verify scaling rules and metrics collection
- Slow scaling response: Check scaling rule thresholds and cooldown periods
- Resource quota errors: Review subscription limits and environment capacity
- Cold start delays: Consider minimum replica configuration
Networking Issues
- Service discovery failures: Verify internal ingress configuration and DNS resolution
- External access issues: Check ingress settings and custom domain configuration
- SSL certificate problems: Verify domain ownership and certificate binding
- Database connectivity: Check managed identity permissions and connection strings
Security Issues
- Managed identity failures: Verify RBAC assignments and Key Vault access policies
- Secret access errors: Check Key Vault references and secret names
- Authentication issues: Review managed identity configuration and API permissions
- Network security: Verify NSG rules and virtual network configuration
Key Takeaways
After completing this lab, you should understand:
- Azure Container Apps provides serverless container hosting with automatic scaling and traffic management
- Microservices architecture benefits from service discovery, internal networking, and independent scaling
- Traffic splitting enables safe deployments with blue-green and canary deployment patterns
- Managed identity eliminates the need for connection strings and provides secure Azure resource access
- Built-in observability offers comprehensive monitoring without additional configuration
- Scaling flexibility supports HTTP, CPU, memory, and custom metric-based auto-scaling
Decision Matrix: When to Use Container Apps
| Scenario | Container Apps | AKS | App Service | Container Instances |
|---|---|---|---|---|
| Microservices | β Recommended | β Good | β οΈ Monolith focus | β No orchestration |
| Event-driven apps | β Recommended | β οΈ Complex setup | β Limited scaling | β οΈ Manual scaling |
| API backends | β Recommended | β Good | β Good | β οΈ Basic features |
| Batch processing | β Recommended | β Good | β Not suitable | β Simple jobs |
| Enterprise apps | β Good | β Recommended | β Good | β Limited features |
| Development/Testing | β Recommended | β οΈ Complex | β Good | β Simple |
Key Decision Factors:
- Serverless scaling: Container Apps scales to zero and handles traffic spikes automatically
- Simplicity: Less operational overhead than AKS with similar container capabilities
- Cost efficiency: Pay only for resources used with automatic scaling
- Integration: Native integration with Azure services and managed identity
Cleanup Instructions
- Navigate to Resource Groups in Azure portal
- Click on βContainerApps-Lab-RGβ
- Click βDelete resource groupβ
- Type the resource group name to confirm
- Click βDeleteβ
Estimated cleanup time: 5-10 minutes