Skip to content

Lab 11: Run containers that scale to zero

At a glance

  • Time: about 30 minutes
  • Region: Southeast Asia
  • You create: 1 Container Apps environment (Consumption) and 1 container app that can scale to zero
  • Cost: very low. An app that scales to zero costs almost nothing when idle. Still delete it at the end.

What you will learn

  • What Azure Container Apps is, and how it differs from a single container (Lab 10).
  • How to create an environment and an app with a public address.
  • How scaling works, including scaling to zero, and what a revision is.

What is different in this environment

  • You work in Southeast Asia, in your own resource group.
  • The environment uses the Consumption plan only. Dedicated plans are blocked with [LAB-P09B-CONTAINER-APPS].
  • You don't send logs to Log Analytics. That workspace bills per GB.
  • Tasks 3 and 4 are extra, to show scaling and revisions.
Diagram: a Container Apps environment holding the app my-app with three revisions, of which only the newest takes traffic, and a scale rule between 0 and 2 replicas.
A container app in a Consumption environment: scale rules, revisions and scale to zero. Select the diagram to open it full size.

Before you start

  • You are signed in to the lab directory (Getting started).
  • Your lab resource group is rg-CLOUD-LAB-GRP-N. Replace N with your group number.
  • Delete the container instance from Lab 10.
  • Each group may have only 1 environment and 1 container app.

Task 1: Create a container app and its environment

  1. Search for Container Apps and select + Create → Container App.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Container app name my-app
    Deployment source Container image
    Region Southeast Asia
    Container Apps environment Create new environment
  3. In the new environment:

    • Environment name: my-environment
    • Environment type (or Plan): Consumption only
    • Zone redundancy: Disabled
  4. On the environment's Monitoring tab, set Logs destination to Don't save logs (or None). Select Create.

    No Log Analytics

    If the form wants a Log Analytics workspace, choose the option that doesn't save logs. If you can't, tell your trainer.

  5. Select Next: Container. Check Use quickstart image and choose Simple hello world container.

  6. Select Next: Ingress. Turn Ingress On, set Ingress traffic to Accepting traffic from anywhere, and the target port to 80.
  7. Select Review + create, then Create. This takes a couple of minutes.

Task 2: Test the app

  1. Select Go to resource.
  2. Select the link next to Application Url.
  3. You should see Your container app is running with a Hello World image.

Task 3: Look at scaling

A container app scales by replicas: copies of the container. You can let it scale to zero when nobody uses it.

  1. In the container app, under Application, select Scale.
  2. Select Edit and deploy, then the Scale tab.
  3. Set Min replicas to 0 and Max replicas to 2.
  4. Select + Add to add a scale rule:

    Setting Value
    Rule name http-rule
    Type HTTP scaling
    Concurrent requests 10
  5. Select Add, then Create. This creates a new revision.

  6. Under Application, select Revision management. Note that the new revision is Active and takes the traffic.
  7. Select the revision and look at its Replicas.

See scale to zero

  1. Wait about 10 minutes without opening the app.
  2. Check Replicas again. The count can fall to 0.
  3. Open the Application Url. The first request is slow, because Azure starts a replica. Check Replicas again.

Think about it

When is scale to zero a good idea, and when is it a bad one? What does the first slow request cost a user?

Task 4: Change a setting and see the revision

  1. Under Application, select Containers → Edit and deploy.
  2. Select the container, and under Environment variables select + Add. Name GREETING, source Manual entry, value Hello from my revision. Select Save, then Create.
  3. Open Revision management. There are now two revisions. Only the newest one takes traffic.

Revisions

A revision is a snapshot of your app. Changing the container or scale settings creates a new one. Older revisions stay, so you can go back.

Task 5: Clean up

  1. Open the container app my-app and select Delete. Confirm.
  2. Delete the environment my-environment. This can take a few minutes.
  3. Check that your resource group has no container app or environment left.

Check your work

  • The Application Url showed the Hello World message.
  • The scale rule http-rule was added, with minimum 0 and maximum 2 replicas.
  • You saw two revisions after changing the environment variable.
  • Your resource group is empty again.

Key points

  • Container Apps runs containers without you managing servers or a cluster, and it scales on rules such as HTTP requests.
  • An environment is the shared boundary for your apps. The Consumption plan charges only for what runs.
  • Scale to zero saves money, but the first request after idle is slow.
  • A revision is an immutable snapshot of the app. A new revision is created when you change the container or scale settings.