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.
Before you start¶
- You are signed in to the lab directory (Getting started).
- Your lab resource group is
rg-CLOUD-LAB-GRP-N. ReplaceNwith 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¶
- Search for Container Apps and select + Create → Container App.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NContainer app name my-appDeployment source Container image Region Southeast Asia Container Apps environment Create new environment -
In the new environment:
- Environment name:
my-environment - Environment type (or Plan): Consumption only
- Zone redundancy: Disabled
- Environment name:
-
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.
-
Select Next: Container. Check Use quickstart image and choose Simple hello world container.
- Select Next: Ingress. Turn Ingress On, set Ingress traffic to Accepting traffic from anywhere, and the target port to
80. - Select Review + create, then Create. This takes a couple of minutes.
Task 2: Test the app¶
- Select Go to resource.
- Select the link next to Application Url.
- 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.
- In the container app, under Application, select Scale.
- Select Edit and deploy, then the Scale tab.
- Set Min replicas to
0and Max replicas to2. -
Select + Add to add a scale rule:
Setting Value Rule name http-ruleType HTTP scaling Concurrent requests 10 -
Select Add, then Create. This creates a new revision.
- Under Application, select Revision management. Note that the new revision is Active and takes the traffic.
- Select the revision and look at its Replicas.
See scale to zero¶
- Wait about 10 minutes without opening the app.
- Check Replicas again. The count can fall to 0.
- 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¶
- Under Application, select Containers → Edit and deploy.
- Select the container, and under Environment variables select + Add. Name
GREETING, source Manual entry, valueHello from my revision. Select Save, then Create. - 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¶
- Open the container app
my-appand select Delete. Confirm. - Delete the environment
my-environment. This can take a few minutes. - 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-rulewas 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.