Get the Container Instances usage in an Azure subscription

Using the Azure management APIs to list Azure Container Instance usage allows us to see how close we are to the limit!

I use Azure Container Instances extensively for a variety of tasks and workloads that change frequently. We typically produce thousands of containers, but letting them spin off into the cloud unplanned is difficult.

Although the cloud has far more capacity by default than any data center I've ever worked with, there are both strict and flexible rules that we must follow.

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 more restrictions, but they are somewhat typical to run into, so you will need to consider them while creating and constructing solutions on a large scale.

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

Usage on a subscription in Azure

We may check the current usage of different providers using the built-in "Usage + quotas" view available through the Azure Portal. For instance, the image below shows how storage accounts are used in two of my areas.

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!

Container Instances REST API

/location//usages is the name of an endpoint. You can easily ascertain your Container Instances' current usage by utilizing the location endpoint.

Authenticate to the Azure REST API

The Azure REST APIs can be authenticated using a variety of resources. I won't go into every authentication option here because it largely depends on how your solutions are put into practice.

Get the usage information for a specific location

I needed to obtain the point-in-time usage for some of my subscribers, even if you might use this as a component of a more complete solution. You can obtain your current use as well as the service limitations by submitting a GET request to this API.

I utilize Postman to immediately obtain the insights.I utilize Postman to immediately obtain the insights.

If you have a valid bearer token, here's how to use Postman to make the API query:

  1. Enter the endpoint URL
  2. Enable Authorization
  3. Configure "Bearer Token"
  4. Input a valid token
  5. Hit "Send"

Making a GET request to the endpoint.

What if I want to increase the limits?

I have raised the restrictions on numerous resources for a variety of subscriptions and geographical areas. Although Azure Support is typically quick to respond and assist with this, it's advisable to schedule your capacity utilization in advance.