Azure Container Apps: Serverless Container Platform Guide
Azure

Azure Container Apps: Serverless Container Platform Guide

Master Azure Container Apps with this comprehensive guide covering serverless containers, deployment patterns, and best practices

March 15, 2024
DevHub Team
4 min read

Azure Container Apps: Serverless Container Platform Guide

Azure Container Apps is a fully managed serverless container service that enables you to run microservices and containerized applications on a serverless platform. This guide explores its features, deployment patterns, and best practices.

Service Overview

graph TB subgraph "Azure Container Apps Environment" direction TB E["Environment"] subgraph "Container Apps" A["App 1"] B["App 2"] C["App N"] end subgraph "Features" D["Auto-scaling"] F["HTTPS Ingress"] G["Service Discovery"] end end A --> D B --> F C --> G classDef azure fill:#0078D4,stroke:#fff,color:#fff class E,A,B,C,D,F,G azure

Key Features

FeatureDescriptionBenefits
Serverless ContainersRun containers without managing infrastructureReduced operational overhead
Auto-scalingScale based on HTTP traffic, events, or metricsCost optimization and performance
MicroservicesBuilt-in service discovery and ingressSimplified architecture
DAPR IntegrationDistributed application runtime supportEnhanced microservices capabilities

Deployment Patterns

Basic Deployment

import { ContainerApp, ContainerAppEnvironment } from '@azure/arm-appcontainers'; const containerApp = { location: 'eastus', managedEnvironmentId: environment.id, configuration: { ingress: { external: true, targetPort: 80 } }, template: { containers: [ { name: 'myapp', image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest', resources: { cpu: 0.5, memory: '1Gi' } } ], scale: { minReplicas: 1, maxReplicas: 10 } } };

Advanced Configuration

# container-app.yaml properties: managedEnvironmentId: /subscriptions/.../environments/myenv configuration: activeRevisionsMode: Multiple secrets: - name: redis-password value: mypassword ingress: external: true targetPort: 80 transport: http allowInsecure: false template: containers: - name: myapp image: myregistry.azurecr.io/myapp:latest env: - name: REDIS_HOST value: redis.internal - name: REDIS_PASSWORD secretRef: redis-password scale: minReplicas: 1 maxReplicas: 10 rules: - name: http-rule http: metadata: concurrentRequests: "100"

Scaling Strategies

HTTP Scaling

MetricDescriptionExample Value
Concurrent RequestsNumber of simultaneous requests100
Response TimeAverage response latency500ms
Request RateRequests per second50

Event-driven Scaling

const eventDrivenScale = { scale: { minReplicas: 0, maxReplicas: 10, rules: [ { name: "azure-queue", azureQueue: { queueName: "myqueue", queueLength: 100 } } ] } };

Networking and Security

Network Integration

graph TB subgraph "Virtual Network" direction TB ACA["Container Apps"] PE["Private Endpoints"] SN["Subnet"] end subgraph "External Services" DB["Azure Database"] CR["Container Registry"] KV["Key Vault"] end ACA --> PE PE --> DB PE --> CR PE --> KV classDef azure fill:#0078D4,stroke:#fff,color:#fff class ACA,PE,SN,DB,CR,KV azure

Security Configuration

# security-config.yaml properties: configuration: secrets: - name: ssl-cert value: base64-encoded-cert ingress: external: true targetPort: 443 transport: http2 allowInsecure: false customDomains: - name: app.example.com certificateRef: ssl-cert dapr: enabled: true appPort: 3000 appProtocol: http

Monitoring and Logging

Application Insights Integration

const monitoringConfig = { configuration: { monitoring: { enabled: true, appInsightsInstrumentationKey: process.env.APPINSIGHTS_KEY } } };

Log Analytics

Log TypeDescriptionRetention
Container LogsApplication stdout/stderr30 days
System LogsPlatform-level events90 days
Audit LogsSecurity and access events365 days

Best Practices

Performance Optimization

  1. Container Image Optimization

    • Use multi-stage builds
    • Minimize image size
    • Implement layer caching
    • Use production-ready base images
  2. Resource Management

    • Set appropriate resource limits
    • Configure auto-scaling thresholds
    • Monitor resource usage
    • Implement graceful shutdown

High Availability

  1. Multi-region Deployment

    const regions = ['eastus', 'westus']; for (const region of regions) { const containerApp = { location: region, // ... configuration }; // Deploy to each region }
  2. Traffic Management

    # traffic-split.yaml properties: configuration: ingress: traffic: - revisionName: myapp-v1 weight: 90 - revisionName: myapp-v2 weight: 10

Troubleshooting Guide

Common Issues

IssuePossible CauseSolution
Container CrashResource limitsAdjust memory/CPU limits
Scaling IssuesIncorrect rulesVerify scaling configuration
Network ErrorsMisconfigured ingressCheck network settings

References

  1. Azure Container Apps Documentation
  2. Container Apps Pricing
  3. DAPR Documentation
  4. Azure Monitor Documentation
  5. Networking Best Practices
  6. Security Guidelines

Related Posts

Container Apps
Serverless
Microservices
DevOps