You've successfully subscribed to Florin Loghiade
Great! Next, complete checkout for full access to Florin Loghiade
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.
Azure Container Apps - Getting our feet wet.

Azure Container Apps - Getting our feet wet.

in

Deploying applications in the cloud may be too much for beginners, but think of Azure Container Apps as a service for determining the technical details behind deploying your app. It offers two ways to do this:

  • Containers: bundle your app's code and everything it needs to run in one image. Azure Container Apps manages these containers, ensuring your app can handle traffic easily.
  • Direct Code: Azure Container Apps lets you deploy your code directly if containers aren't your thing. This gives you flexibility in how you want to get your app up and running in the cloud.

At the end of this article, you should have a better understanding of the Azure Container Apps and even have a good demo :)

Serverless Container Deployment

Traditionally, deploying applications could be cumbersome, involving hands-on server setup, intricate container orchestration, and detailed deployment steps. Azure Container Apps addresses these problems head-on with its fully managed Kubernetes backdrop, streamlining the development process and allowing developers to focus on container images or deploying code from diverse sources, such as GitHub or container registries.

Here's a breakdown of Azure Container Apps' core functionalities:

  • Effortless Deployment of Applications: Facilitates containerized applications or code deployment from various sources, negating the need for hands-on server management.
  • Centralized Application Management: Offers a unified platform for managing all containerized applications, streamlining tasks related to monitoring, scaling, and configuration.
  • Integrated Observability: It provides deep insights into application health and performance with comprehensive monitoring tools.
  • Intelligent Auto-Scaling: Employs automatic scaling of container instances aligned with traffic patterns, ensuring efficient use of resources and cost reduction.
  • Support for Event-Driven Architectures: This feature enables the development of dynamic and scalable applications through seamless integration with Azure Event Grid and similar eventing mechanisms.

The Serverless Advantage

The serverless model has changed the application development landscape, offering a shift away from the intricacies of server management. Azure Container Apps fully adopts this innovative approach, unblocking developers from concentrating on designing their applications without the distractions of server setup, configuration, or scalability concerns. This shift carries along powerful technical benefits:

  • Streamlined Development Cycle: By eliminating the need for server management, the development process becomes more efficient, significantly speeding up application delivery. No more setting up n+1 Terraform templates for AKS deployments.
  • Operation Simplification: ACA manages the infrastructure, reducing the operational load on the infrastructure teams.
  • Cost-Efficiency: Leveraging a serverless model that charges based on usage, Azure Container Apps ensures financial savings by billing only for the resources used by applications, but that only applies if you're app is not huge where the serverless model fades away fast from a competitive price perspective.
  • Dynamic Scalability: Azure Container Apps can dynamically scale exactly as an AKS cluster can; however, this is built in and has more PaaS-like scalability than the pseudo-IaaS of AKS. Fast fire scaling out and scaling in

Use Cases For Azure Container Apps 

Azure Container Apps shows its strength in various development contexts, particularly those that benefit from its serverless framework and the advantages of containerization. Here's where it excels:

  • Microservices Deployment: Built with microservices in mind, ACA provides a seamless environment for deploying these small, independent, modular components of a larger ecosystem. The platform supports deploying and orchestrating many microservices, streamlining their management within the application.
  • API Endpoints Development: Easily develop and deploy RESTful APIs, making the application's core functionalities available to clients.
  • Background Processes: Extensive background operations, such as data analysis or batch processing, are executed easily because of the KEDA integration. This integration enables decoupling heavy-duty tasks from the main application flow, enhancing overall efficiency and performance.
  • Event-Driven Systems: With default integration with event-driven architectures, you can build dynamic applications that react instantly to real-time events. It supports Azure Event Grid and other event services, which allow you to scale to zero or burst scale based on the number of events.

Azure Container Apps vs. Azure Kubernetes Service: 

While Azure Container Apps and Azure Kubernetes Service facilitate containerized application deployment, they have distinct use cases. Here's a small comparison of their fundamental differences to help you choose the right platform:

Feature Azure Container Apps Azure Kubernetes Service
Management Model Fully managed Self-managed
Infrastructure Orchestration No orchestration required Manual or automated Kubernetes cluster orchestration
Ideal Use Cases Simpler deployments, serverless workloads, microservices Complex deployments requiring fine-grained control
Developer Focus Business logic and application code Infrastructure management, Kubernetes expertise
Cost Pay-per-use model Virtual machine costs for cluster nodes

When choosing between ACA and AKS, consider factors like the complexity of your application, your team's expertise, and your desired level of control. Azure Container Apps is a strong choice for simpler deployments or scenarios with attractive serverless benefits. Contrariwise, AKS might be a better fit for complex deployments requiring granular control over the underlying infrastructure.

Advanced Features of Azure Container Apps

Azure Container Apps goes beyond mere application deployment, presenting an extensive suite of advanced functionalities that empower developers to build complex and scalable containerized applications:

  • Dapr Integration: Azure Container Apps offers seamless Integration with Dapr, a distributed application runtime designed for event-driven microservices. This allows you to tap into Dapr's comprehensive APIs for service invocation, state management, and messaging tasks. The result? The creation of more autonomous, robust microservices that are simpler to maintain and scale. 
    • I suggest taking a look at https://dapr.io/ as it's an excellent system which I use in production.
  • Support for Multi-Container Applications: Moving past the limitations of single-container deployments, Azure Container Apps enables the definition and management of applications composed of multiple, interconnected containers. This capability is necessary when developing and deploying complex microservices architectures, giving developers precise control over scaling application components based on their unique resource needs.
  • Revision Management: Keeps track of the various iterations of your containerized applications, making it easy to revert to prior versions when needed. This feature is instrumental in conducting A/B testing, allowing for deploying different application revisions and evaluating user responses to select the best version.
  • Blue/Green Deployments: Blue/Green deployment is a strategy to minimize risks during new releases. This method entails gradually directing traffic from the current version, blue to the latest version, green, and closely monitoring performance to ensure a smooth transition or a quick rollback if problems arise.
  • Custom Routes and Ingress: ACA offer the flexibility to establish custom routes for your applications, enhancing user accessibility. Utilizing HTTP or TCP ingress rules, developers can precisely expose application endpoints according to specific requirements.
  • Integrated Monitoring and Logging: You get in-depth visibility into application health and performance through its integration with Azure Monitor. This enables monitoring metrics, logs, and events, facilitating early detection and resolution of any arising issues.
  • Integration with Azure Functions and Spring Apps: The service enhances the development ecosystem by allowing integration with Azure Functions and Spring Apps within the same computing environment. This integration supports deploying serverless functions, event-driven logic, and Spring-based applications with containerized solutions, promoting a cohesive application development strategy.

How do I get started?

While Azure Container Apps don't directly require code within the platform configuration, they facilitate containerized application deployment. Here are some code examples demonstrating how containerized applications might be built and deployed with Azure Container Apps:

1. Python Flask Application (Simple Hello World):

This example showcases a basic Python Flask application that logs the current date and time and displays a personalized message:

from flask import Flask
from datetime import datetime

app = Flask(__name__)

@app.route("/")
def hello_world():
    current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    message = f"Florin Loghiade was here! It is currently {current_time}"
    return message

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

2. Building the Dockerfile:

FROM python:latest 

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt 

COPY . .

CMD ["python", "app.py"]

This Dockerfile:

  • Uses a base Python image using the latest version (never use in production)
  • Sets the working directory within the container to /app.
  • Copies the requirements.txt file (containing application dependencies) and installs them using pip.
  • Copies the entire application code directory.
  • Defines the command to execute (python app.py) when the container starts, running your Flask application.

3. Build and Push with AzCLI:

Here's the az acr build command to build and push the container image directly to your Azure Container Registry:

#build the image
az acr build --registry <your-acr-name> --image <your-acr-name>.azurecr.io/a-flask-app:latest .

Explanation:

  • Replace <your-acr-name> with your actual ACR name.
  • This command:
    • Uses the az acr build command for building and pushing the image.
    • Specifies the ACR registry with the --registry option.
    • Defines the target image name and tag (<your-acr-name>.azurecr.io/a-flask-app:latest) using the --image option.
    • The final argument (.) specifies the context (current directory) where the Dockerfile resides.

4. Deploying with Azure CLI:

Once your container image is built (using docker build -t a-flask-app .), you can leverage the Azure CLI to deploy it to Azure Container Apps. Here's a basic example:

# create a resource group
az group create \
  -n containerDemo \
  -l westeurope

# create an app environment
az containerapp env create \
  --name an-env \
  --resource-group containerDemo \
  --location westeurope

# deploy the container
az containerapp create \
  --name a-flask-app \
  --resource-group containerDemo \
  --registry-identity system \
  --registry-server <acrName>.azurecr.io \
  --image '<acrName>.azurecr.io/a-flask-app:latest' \
  --environment 'an-env' \
  --min-replicas 2 \
  --max-replicas 4 \
  --ingress external \
  --query properties.configuration.ingress.fqdn \
  --target-port 5000
  • Resource Group Creation:
    • Creates a resource group named "containerDemo" in the "westeurope" region.
  • Environment Setup:
    • Creates a Container Apps environment named "an-env" within the resource group.
  • Application Deployment:
    • Deploys a container app named "a-flask-app" with the following configurations:
      • Uses the "system" registry identity for authentication.
      • References your Azure Container Registry (ACR) image.
      • Deploys into the "an-env" environment.
      • Scales between 2 and 4 replicas.
      • Enables external ingress for public access.
      • Outputs the fully qualified domain name (FQDN) of the application.
      • Specifies the target port 5000 for incoming traffic.

And voila!

Final thoughts

These examples provide a starting point for building and deploying containerized applications with Azure Container Apps. The specific code and deployment configurations will vary depending on your application's complexity and requirements.

Azure Container Apps emerges as a compelling solution for building and deploying modern containerized applications at scale. Its serverless approach, coupled with many advanced features, empowers developers to focus on crafting exceptional applications while minimizing operational overhead. Azure Container Apps streamlines the development lifecycle, fosters scalability, and ensures cost-effectiveness by offering a fully managed platform.