Azure Container Instance – Beginner’s Guide

Filed Under: Random
Azure Container Instance

Hello, readers! This article talks about Azure Container Instance with detailed information around it’s setup.

So, let us begin!! 馃檪


What is an Azure Container Instance (ACI) Service?

In the world of virtual machines and containers, one thing that has always been a point of concern is resource optimization and cost estimation as well. Depending on the use cases, we often choose services from the public cloud providers.

To get rid of managing the virtual machines, we may choose the AKS or GKE for the same. Although it has its features, we still sense a need to orchestrate the service from the admin’s perspective and even manage the backend resources in terms of nodes and auto-scaling as well.

Based on some simpler use cases, we may want to get rid of this server (resource) based set up and we may wish to have a service that hosts our applications as containers with minimal configurations needed to manage.

This is when Azure Container Instances (ACI) come into the picture.

Azure Container Instance is a service provided to us by Azure that is serverless in nature. Yes, that is completed orchestrated, and managed at the backend by Azure. We can spin up containers within a fraction of seconds and the resource utilization is taken care of by them. We thus do not need to manage the Virtual machines or nodes at the backend.

This server-less model is useful for smaller and lightweight applications such as build jobs, automation tasks, isolated app services, etc.


Important Terminologies in Azure Container Instances to know!

  • Container Group: It is a group of containers. That is, it is an isolated infrastructure within which we can have multiple server less containers running for the entire application service. The containers in the container group tend to share the volume space, resources, local network configurations, etc. They get scheduled on the same host machine.
  • We can deploy the containers within the Azure Container Instances either through YAML files or Resource manager templates.
  • For the purpose of Storage, we have the below set of options to associate the containers to the storage volumes in Azure –
  1. Azure File share
  2. Empty directory volume
  3. Secret, etc.
  • For the purpose of resource allocation to the container groups, we need to check the Resource availability for the entire Azure subscription’s region within which the container instance service is allocated.

Deploy a Container Group in Azure Container Instance Service

Having understood the background of Container Instance, let us now try to deploy one container group using the below YAML approach-

apiVersion: 2019-12-01
location: <location>
name: <Container Group name>
properties:
  containers:
  - name: <name of container 1>
    properties:
      image: <either public image or private image from acr>
      resources:
        requests:
          cpu: <cpu required for container 1>
          memoryInGb: <memory required for container 1>
      ports:
      - port: <port no.>
      - port: <we can mention all the ports that we want the app to be exposed to>
  - name: <name of container 2>    
    properties:
      image: <image>
      resources:
        requests:
          cpu: ..
          memoryInGb: ..

#we can have more containers in a container group as per our requirement

osType: Linux

ipAddress:
type: <Public or private>
ports:
- protocol: <protocol for the mentioned port>
port: <port no. specified in container property>
tags: {exampleTag: tutorial}
type: Microsoft.ContainerInstance/containerGroups

Use the below command to create the container group in an azure subscription using azure CLI-

az container create --resource-group <resource group name> --file <yaml_file_name.yaml>
  • We need to mention the resource group within which we want the container group to reside.
  • In the properties of the first container, we can mention the port number. Rest all the containers will run as a side car to the first container of the container group.

In case, if we wish to create a container instance based on a certain image from a private ACR, we can do so by adding the below configuration to the properties section of the YAML-

imageRegistryCredentials:

  - server: <server login name>
    username: <service principal application id>
    password: <service principal password>

Network configurations for Azure Container Instances

  • In order to have a secured communication amongst other Azure services, we can deploy the container group in an Azure Virtual Network.
  • We will be needing the below resources configured for the set up-
  1. An Azure Virtual Network (Azure VNet)
  2. A subnet created within the Azure VNet
  3. The subnet can be used only for container groups.
  4. Network Profile
  • The subnet cannot contain any other resource except Container groups.
  • Using Azure VNet for ACI, we cannot add Readiness probe or Liveness probe to the containers.
  • At the moment, only Linux containers are supported in a container group deployed to a virtual network.

In order to deploy a Container group in an Azure VNet, we can add the below code within the YAML file-

ipAddress:
    type: Private
    ports:
    - protocol: <protocol>
      port: '<port no. mentioned in properties section of container>
  osType: Linux
  restartPolicy: Always
  subnetIds:
    - id: <subnet id>
      name: <subnet name>


We can also create the container group through azure CLI using the below command-

az container create \
  --name <container group name> \
  --resource-group <resource group name> \
  --image <image link> \
  --vnet <vnet name> \
  --subnet <subnet name>

Conclusion

By this, we have reached the end of this topic. Feel free to comment below, in case you come across any questions. For more such posts related to Azure Services, Stay tuned with us.

Till then, Happy Learning!! 馃檪

close
Generic selectors
Exact matches only
Search in title
Search in content