Azure App Containers

July 6, 2022    Azure Containers Kubernetes Dapr Project Tye DevOps Agile

Azure App Containers

I’ve had some time to dig into Azure App Containers . I have limited container experience, but have been interested and learning in spurts about containers over the last few years. In my opinion, containers have become the best way to run applications. I’m interested in cheaper, quicker and easier way to host containers without Kubernetes. I’d like to have them communicate between each other. I’ve also been interested in Dapr to help with microservices, pub/sub and secret management. After hearing about Azure App Containers at Microsoft Build 2022 , it seems like another Microsoft achievement to let developers focus on writing code to meet business outcomes and not having to worry about infrastructure.

"Azure Container Apps enables you to run microservices and containerized applications on a serverless platform" 

from MS Docs Overview

Features

  • pay by the second
  • built on K8s, but you don’t have to know about it
  • Dapr is built in (if you want, helps with microservices)
  • KEDA Open source auto scaling
  • Envoy for ingress
  • serverless
  • scaling
  • fully managed, not locked in
  • split traffic for A/B testing
  • custom domains
  • event driven

Learning Path

I started by watching videos from .Net Conf 2022 and MS Build 2022 (linked in the resources section below) to get an overview. I then ran through the quick start and then followed more doc steps. The Azure Cli is really slick and makes walking through these steps easy. There are a lot of pieces to put together and I had some struggles.

I had a decent foundation knowledge of containers and some practice using Docker in the past. You’ll need that as well as you go beyond the tutorials.

Approach to Create an application

  • Create Docker image files and build locally (or use az acr build)
  • Run locally with Project Tye or docker compose
  • setup environment variables for urls to enable communication between the containers
  • Handle CORS
    • In a .Net Api Program.cs
      var urlFromEnvironmentVar = Environment.GetEnvironmentVariable("frontUrl");
      builder.Services.AddCors(options =>
      {
          options.AddPolicy(
            name: MyAllowSpecificOrigins,
            policy =>
            {
                policy.WithOrigins(urlFromEnvironmentVar);
            });
      });
      
  • Add Dapr Side car
    • this example uses a storage account. I didn’t get this example to work, but must have done something wrong.
    • options to add to the az containerapp create command --enable-dapr \ --dapr-app-id nodeapp \--dapr-app-port 3000
    • Do you need to update Dapr as time go on? How do you do that?
  • Create Azure pieces with the cli
  • Check Https Ingress
  • Update with Azure Container Registry push (and CI), but get Github Actions or Azure DevOps pipelines going right away
  • Auth
  • Manage Secrets
    • Use Dapr and the Azure UI for secrets.
    • add --secrets "xkey=yvalue to az containerapp create
    • I think we need to move them to Azure KeyVault, but I haven’t seen any examples
  • Add in monitoring with Azure App Insights, built in Azure logs or another solution .

Then learn about environments, revisions, monitoring, health checks, scaling with KEDA, using the Dapr api for state storage, etc.

The Microsoft Docs cover the information really well. Your challenge is how to understand all the pieces, think about the needs of your application and put them together.

Environment Variables

I started with a web front end and back end for an example. I need to set a configurable api address in the web front end. I’m choosing to use an environment variable.

Docs Communicate between microservices has a node app example, but I’d like to use .Net with Javascript.

First, pass in --env-vars API_BASE_URL=https://$API_BASE_URL \ to az containerapp create. You could have a different container app for test than production.

Then you need to read the environment variable. There are different options depending on your app.

Faster Development in a Docker Container for web apps

To reduce the time from change to running, you need to install .NET debugging tools inside the container to communicate back to your ide

Adding this to your dockerfile should work

RUN apt-get update \    
  && apt-get install -y --no-install-recommends unzip \
  && rm -rf /var/lib/apt/lists \
  && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /remote-debugger

Conclusion

I’m excited about the prospects of using Azure App Containers. I think there is a big potential. If/when I get a chance to create a new app, I’m going to lobby to use Azure App Containers to host the web and api instead of using Azure App Service. That will leave the possibility open to use a microservice approach when it makes sense, instead of only adding functionality to the api or in Azure Functions that are off on there own.

I still have more to learn and will add more to this page as I make progress.



Watch the Story for Good News

Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads!

Use Brave

Also check out my Resources Page for referrals that would help me.


Swan Bitcoin referral image
Use Swan Bitcoin to onramp with low fees and automatic daily cost averaging and get $10 in BTC when you sign up.