Lesson 4 of 4 Azure Container Services

Sizing and Scaling Containers

This lesson explains how CPU and memory are allocated and how scaling works in Container Instances and Container Apps.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how container resources are set in Container Instances and Container Apps.
  • Describe Container Apps scale rules and scale to zero.
  • Choose a service and scaling configuration for a workload.

Sizing in Container Instances

In ACI, each container specifies resource requests: a number of CPU cores (which can be fractional, such as 0.5) and memory in GB. The container group's resources are the sum of its containers' requests, and the maximum per group depends on the region and OS type (commonly up to 4 vCPUs and 16 GB for standard Linux groups). Containers can also set limits that cap them within the group's resources. Billing is per second for the requested vCPU and memory.

The resources of a running container group cannot be changed. To resize, update the CPU and memory in the YAML file or template and redeploy the group, which restarts its containers, or delete and recreate it. Because ACI has no autoscaling, scaling out means deploying additional container groups, for example from automation, and placing them behind a load balancer or Application Gateway yourself.

Troubleshooting

Resizing a container group

Exam skills 3.3.4

Find the right way to resize a container group.

Log in to try this activity Interactive activities are free with an account.

Sizing in Container Apps

In Container Apps, CPU and memory are allocated per container in fixed combinations, such as 0.25 vCPU with 0.5 GiB, 0.5 vCPU with 1 GiB, up to 4 vCPUs with 8 GiB in the Consumption profile, with larger options in dedicated workload profiles. Changing CPU or memory creates a new revision, so the change rolls out without manual redeployment.

Scaling in Container Apps

Container Apps scales the number of replicas of a revision between a minimum (default 0) and a maximum (default 10) using scale rules based on KEDA (Kubernetes Event-driven Autoscaling). Rule types are HTTP (concurrent requests per replica), TCP (concurrent connections), custom rules for any KEDA scaler, such as Azure Service Bus queue length, Azure Storage queue length or Kafka lag, and CPU or memory utilization. If no rule is defined, a default HTTP rule applies for apps with ingress.

With a minimum of 0, an app scales to zero when idle and incurs no compute charges in the Consumption profile, but the first request after idle has a cold start. Setting a minimum of 1 or more keeps replicas ready. CPU and memory rules cannot scale to zero, because they need running replicas to measure. The table below summarizes the scaling differences.

Container Instances
Change CPU or memoryRedeploy the container group
Scale outDeploy more container groups yourself
Scale to zeroStop or delete the group
Choose when Fixed-size tasks and simple containers
Container Apps
Change CPU or memoryNew revision, rolled out automatically
Scale outScale rules on HTTP, TCP, CPU, memory or events
Scale to zeroBuilt in (minimum replicas 0)
Choose when Variable-load services and event processing

The following diagram shows replicas following the queue length.

Capacity that follows an order queue and costs nothing when it is empty. Azure Container Apps with a custom scale rule of type azure-servicebus on the queue's message count, a minimum of 0 replicas and a maximum sized for the burst, adds replicas during promotions and scales to zero afterwards.
The values are schematic.
Scenario questions

Scale rules

Exam skills 3.3.4

Choose the scale rule and replica settings for each Container Apps workload.

Log in to try this activity Interactive activities are free with an account.
Worked example

Scaling on a queue

A container processes orders from an Azure Service Bus queue. Most of the day the queue is empty, but promotions create bursts of thousands of messages. The company wants processing capacity to follow the queue length and to pay nothing when the queue is empty. Which service and configuration should you use?

Use Azure Container Apps with a custom scale rule of type azure-servicebus on the queue's message count, a minimum of 0 replicas and a maximum suited to the burst. A Container Apps job with an event-driven trigger is also suitable when each execution processes a batch and exits. Container Instances cannot scale automatically, and a CPU rule cannot scale to zero.

Check yourself

Why can't a Container Apps rule based on CPU scale an app to zero?

Show answer

CPU and memory rules need running replicas to measure, so they cannot bring the count to zero.

Exam Tips

Remember for the exam

  • ACI resources cannot change on a running group; redeploy to resize.
  • Container Apps replicas scale between a minimum (default 0) and maximum (default 10).
  • Event-driven scaling uses KEDA-based custom rules.
  • Scale to zero saves cost but causes cold starts; set the minimum to 1 or more to avoid them.