Deploying Containers on Azure

This guide outlines the primary methods and services for deploying your containerized applications on Microsoft Azure. Whether you're using lightweight container instances or a full-fledged Kubernetes orchestrator, Azure provides robust solutions to meet your needs.

Choosing the Right Deployment Service

Azure offers several services tailored for container deployment. The best choice depends on your application's complexity, scalability requirements, and management preferences.

  • Azure Container Instances (ACI): Ideal for simple container deployments, single containers, batch jobs, or development/testing scenarios. It offers rapid startup and doesn't require managing underlying infrastructure.
  • Azure Kubernetes Service (AKS): The premier managed Kubernetes service on Azure. It's suited for complex, microservices-based applications requiring advanced orchestration, scaling, and high availability.
  • Azure Container Apps: A serverless platform built on Kubernetes that simplifies deploying containerized applications and microservices. It's designed for modern apps and scales automatically with events.
  • Azure App Service (Web Apps for Containers): A fully managed platform for building, deploying, and scaling web apps and APIs. You can deploy container images directly to App Service.

Deploying with Azure Container Instances (ACI)

ACI allows you to run containers in Azure without managing virtual machines. It's perfect for scenarios where you need a container up and running quickly.

Using the Azure CLI:

You can deploy a container group using a simple Azure CLI command:

az container create \
    --resource-group myResourceGroup \
    --name myContainer \
    --image myDockerImage:latest \
    --dns-name-label mycontainer.eastus.azurecontainer.io \
    --ports 80

This command creates a container group named myContainer in the myResourceGroup, using the specified Docker image. It exposes port 80 and assigns a DNS label for external access.

Tip: For more complex configurations, such as deploying multiple containers, mounting volumes, or setting environment variables, consider using ARM templates or Bicep for ACI deployments.

Deploying with Azure Kubernetes Service (AKS)

AKS provides a managed Kubernetes experience, handling the complexities of orchestrating containers at scale.

Key Concepts for Deployment in AKS:

  • Deployments: Define the desired state of your application, including the container image and the number of replicas.
  • Pods: The smallest deployable units in Kubernetes, typically containing one or more containers.
  • Services: Abstract network access to pods, enabling stable endpoints for your application.
  • Ingress: Manages external access to services in a cluster, typically HTTP/S, providing load balancing, SSL termination, and name-based virtual hosting.

Example Deployment (YAML):

Create a deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: nginx:latest
        ports:
        - containerPort: 80

And a service.yaml file to expose the deployment:

apiVersion: v1
kind: Service
metadata:
  name: my-web-service
spec:
  selector:
    app: web
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer

Apply these configurations to your AKS cluster:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Deploying with Azure Container Apps

Container Apps offers a serverless, event-driven approach to deploying containers. It's built on open standards like Kubernetes and Dapr.

Key Features:

  • Automatic scaling based on HTTP traffic or events.
  • Built-in support for KEDA (Kubernetes Event-driven Autoscaling).
  • Secure and isolated environments.
  • Simplified deployment from container images.

Example Deployment using Azure CLI:

First, create a Container App environment:

az containerapp env create --name my-env --resource-group myResourceGroup --location eastus

Then, create the Container App:

az containerapp create \
  --name my-container-app \
  --resource-group myResourceGroup \
  --environment my-env \
  --image mcr.microsoft.com/azuredocs/aci-helloworld \
  --target-port 80 \
  --ingress external \
  --query configuration.ingress.fqdn