Configuring Azure Container Instances

The ACI service by Microsoft Azure provides us with a fast and easy way to run containers in the cloud without worrying about the management part of virtual machines or having to learn about new tools. This service is designed to be as quick as possible and ease the process of getting a container up and running in the cloud. Furthermore, it is possible to launch a container by executing a simple Azure CLI command, such as the following:

az container create --resource-group myResourceGroup 
--name cache-container
--image redis:alpine
--cpu 1
--memory 1
--dns-name-label cache-container
--ports 6379

The ACI service is the ideal service for testing and running containers in Azure. Hence, the ACI service allows us to lower our infrastructure costs by taking advantage of per-second billing. For that reason, the ACI service is also the favorite service for continuous integration and continuous pipeline purposes. The following steps show you how to deploy the catalog service on ACI:

  1. Let's start by creating a new resource group so that we can group our containers. Use the following command to do so:
az group create --name handsOnContainerServices --location "West Europe"
  1. We can proceed by getting the registry username and password of the service account of the container registry using the following command: 
az acr credential show -n <container_registry_name>
  1. After creating the group, we will need to execute the Azure CLI command using a Bash script from the GitHub repository called aci-deploy.sh:
#!/bin/bash
# Set the service group name
export resource_group=handsOnContainerServices
# Set the registry address
export registry_address=<registry_address>
# Set the registry username
export registry_username=<registry_username>
# Set the registry password
export registry_password=<registry_password>
# Set the api ASPNETCORE_ENVIRONMENT variables
export environment=Stage
# Set the sql container name
export sql_name=catalog-db
# Set the sql admin password
export sql_admin_pass=P@ssw0rd
# Set the event service bus name
export esb_name=catalog-esb
# Set the event service bus username
export rabbitmq_user=guest
# Set the event service bus password
export rabbitmq_pass=guest
# Set the cache container name
export cache_name=catalog-cache
# Set the service name
export api_name=catalog-api


az container create --resource-group ${resource_group}
--location westeurope
--name ${sql_name}
--image microsoft/mssql-server-linux
--cpu 1
--memory 1
--dns-name-label ${sql_name}
--ports 1433
--environment-variables ACCEPT_EULA=Y SA_PASSWORD=${sql_admin_pass}

az container create --resource-group ${resource_group}
--location westeurope
--name ${esb_name}
--image rabbitmq:3-management
--cpu 1
--memory 1
--dns-name-label ${esb_name}
--ports 5672
--environment-variables RABBITMQ_DEFAULT_USER=${rabbitmq_user} RABBITMQ_DEFAULT_PASS=${rabbitmq_pass}

az container create --resource-group ${resource_group}
--name ${cache_name}
--image redis:alpine
--cpu 1
--memory 1
--dns-name-label ${cache_name}
--ports 6379

az container create --resource-group ${resource_group}
--location westeurope
--name ${api_name}
--image ${registry_address}/catalog_api:v1
--cpu 1
--memory 1
--dns-name-label ${api_name}
--ports 80
--ip-address public
--environment-variables ASPNETCORE_ENVIRONMENT=${environment}
--registry-password=${registry_password}
--registry-username=${registry_username}

The script mostly runs five different instructions for the creation of new instances of these containers:

    • It declares information regarding the containers, such as the resource group, the names to assign to the containers, and some additional environment variables.
    • It executes the az container create command to create and run microsoft/mssql-server-linux.
    • It executes the az container create instruction to create and run the rabbitmq:3-management-alpine image, and it uses the rabbitmq_user and rabbitmq_pass environment variables to set the default user for the RabbitMQ instance.
    • It deploys the Redis cache instance using redis:alpine.
    • Finally, it executes az container create to create and deploy the catalog_api image that's already present in the Azure Container Registry repository by specifying the registry URL. 
Please note that the execution order follows the same logic of the dependencies of these containers; therefore, the API container is run last.
Note that, to keep the demo as simple as possible, the aci-deploy.sh script creates the catalog service container using --ip-address public, which means that our container can be accessed by anyone. Directly exposing an API without any reverse proxy and an API gateway is strongly discouraged in a production environment so that you avoid exposing your containers to the outside world. 

Now that we've executed the script, we can see the result by signing into the Azure portal (https://portal.azure.com/#) and checking our container in the Container instances section:

As you can see, there are four container instances up and running. All of them are running on DNS using the --dns-name-label parameter and can access each other through their addresses. Hence, it is possible to call the container API using the address that was generated by our shell script. We can also check the statistics and the properties associated with the container by clicking on the name of the container:

Finally, we can call the health check HTTP route from our browser to verify that all of the dependencies are correct:

http://catalog-api.westeurope.azurecontainer.io/health

The preceding process describes how to deploy the catalog service into the ACI product. Although ACI are powerful and easy to deploy, they lack some minimal out-of-the-box features, such as SSH, monitoring, and configuration management. Therefore, it becomes hard to manage container instances in a production environment. In the next section, we will focus on a different hosting process that uses app service technologies to host the application called app services. This way of working is more focused on the hosting of web applications and web services; therefore, it provides a set of tools and features for the monitoring and the configuration of the application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.70.255