Get the Container Instances usage in an Azure subscription

Using the Azure management APIs to list Azure Container Instance usage helps us understand how close to the limits we are!

Tobias Zimmergren
Tobias Zimmergren

To ensure we have reliability and that we don't get any service degradation of the tools and services we build for customers, one must understand the service limitations in Azure.

Azure Container Instances is a service I rely heavily on for many operations and dynamic workloads. We create thousands of containers regularly - but it's not easy to just let them spin off into the cloud without proper planning.

While the cloud is inherently offering a lot more capacity than any data center I've ever had the chance to work with, there are both hard and soft limitations by which we need to abide.

As an example, here are some of the default limitations for Azure Container Instances:

  • 100 Standard SKU container groups per region, per subscription.
  • 60 containers per container group.
  • 20 volumes per container group.
  • 300 container group creates per hour.
  • 100 container group creates per 5 minutes.
  • 300 container group deletes per hour.
  • 100 container group deletes per 5 minutes.

There are further limitations, but these are relatively common to bump into - and if you are designing and building solutions at scale, you will need to take these into account.

Read more:

But, how do we know if we're close to these container limitations?

Usage on a subscription in Azure

From the Azure Portal, we have the built-in view of "Usage + quotas", where we can see the current usage of various providers. As an example, the below picture illustrates the usage of storage accounts in two of my regions.

Unfortunately, Container Instances is one of the services not available on the list here. Therefore, it is difficult to know if and when we will hit the roof of the service limitations.

Usage and quotas, as seen from the Azure Portal.

We can see the usage and quotas in the Azure Portal; however, we can't see Container Instances here. We need to find another way!

Hello, Container Instances REST API

In the API docs of Azure Container Instances, there is an endpoint named /location/<region>/usages. Using the location endpoint, you can quickly determine the current usage for your Container Instances.

Authenticate to the Azure REST API

There are many resources available to authenticate to the Azure REST APIs. I will not walk through each authentication option here, as this heavily depends on how you implement your solutions.

Learn more about authentication:

Get the usage information for a specific location

While you can implement this as part of a more comprehensive solution, I needed to get the point-in-time usage for some of my subscriptions. Making a GET request to this API gives you both the service limitations, and your current usage.

To get the insights quickly, I use Postman.

I am using Postman to get data from an Azure REST API.

Here's how to make the query to the API using Postman if you have a valid bearer token, for example:

  1. Enter the endpoint URL (https://management.azure.com/subscriptions/SUBSCRIPTION_ID/providers/Microsoft.ContainerInstance/locations/YOUR_LOCATION/usages?api-version=2021-09-01).
  2. Enable Authorization
  3. Configure "Bearer Token"
  4. Input a valid token
  5. Hit "Send"

For my scenario, this was enough. However, I also have a broader scope of objectives to automate this. I need to report it back to dashboards and set off an alert when it comes too close to the limits in any given region. That, perhaps, will find its way into another post in the future.

Making a GET request to the endpoint:

  • GET https://management.azure.com/subscriptions/SUBSCRIPTION_ID/providers/Microsoft.ContainerInstance/locations/YOUR_LOCATION/usages?api-version=2021-09-01

When the query executes successfully, you'll get a result similar to this one:

{
    "value": [
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/ContainerGroups",
            "unit": "Count",
            "currentValue": 92,
            "limit": 300,
            "name": {
                "value": "ContainerGroups",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/standardCores",
            "unit": "Count",
            "currentValue": 268,
            "limit": 1200,
            "name": {
                "value": "StandardCores",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/standardK80Cores",
            "unit": "Count",
            "currentValue": 0,
            "limit": 18,
            "name": {
                "value": "StandardK80Cores",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/standardP100Cores",
            "unit": "Count",
            "currentValue": 0,
            "limit": 0,
            "name": {
                "value": "StandardP100Cores",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/standardV100Cores",
            "unit": "Count",
            "currentValue": 0,
            "limit": 0,
            "name": {
                "value": "StandardV100Cores",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/DedicatedContainerGroups",
            "unit": "Count",
            "currentValue": 0,
            "limit": 0,
            "name": {
                "value": "DedicatedContainerGroups",
                "localizedValue": "Container Groups"
            }
        },
        {
            "id": "/subscriptions/SUBSCRIPTION_GUID/providers/Microsoft.ContainerInstance/locations/westeurope/usages/dedicatedCores",
            "unit": "Count",
            "currentValue": 0,
            "limit": 3000,
            "name": {
                "value": "DedicatedCores",
                "localizedValue": "Container Groups"
            }
        }
    ]
}

In the response from the API, there are two important values.

  • limit: The service limitation for the given service in your specified location.
  • currentValue: How much you are currently consuming. This value should ideally be lower than the limit, else you're hitting the roof.

Voila. We have learned what our current usage is for a given subscription, and we can now easily take action as appropriate.

What if I want to increase the limits?

You can request an increase in the service limits for your Azure services. You need to file a new ticket to support, ideally from the Azure portal,  and specify the subscription, region, service, and the quotas you need to have increased.

Submit a new ticket to Azure Support to request a quota increase.

I have increased the limits of many resources across many subscriptions and regions. Azure Support is usually responsive in helping out with this, but it's always best to plan ahead for your capacity usage.

Thanks for reading.

ContainersAzure

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Mastodon