Tuesday, August 7, 2018

Working with Azure Container Instances



----
Working with Azure Container Instances
// StarWind Blog

Azure Container Instances

Introduction

In April 2018, Microsoft announced that Azure Container Instances (ACI) is now ready for production usage. Azure Container Instances offers the fastest and simplest way to run a container in Azure, without having to provision any virtual machines. With Azure Container Instances, you can easily run containers with a single command and in a few seconds. In the initial ACI preview, Microsoft said that customers were mainly using the services for batch processing and continuous integration. To get information about pricing, please read this page: https://azure.microsoft.com/en-us/pricing/details/container-instances/

ACI lets you create Linux or Windows Containers without the need to deploy a Container host, so in other words, ACI is serverless, and it works like a charm!

So in this article, I will describe how to create a simple Container using Azure Container Instances (ACI). In the first part, I will describe ACI using the Azure Portal and the command line, and in the second part, I will describe Azure Container Registry.

Note: ACI can be controlled by Kubernetes using portable API Connector. You don't need to run Kubernetes in Azure to use this feature; all you need is a public IP address for the ACI Kubernetes APIs.

Getting Started

How Azure Container Instances works? ACI will simply assign an existing Virtual Machine to your container, so you will be up and running in seconds. Once deployed, your container is up and running with either a public IP address or a private internal address. To go further with Azure Container and orchestration, I advise you to read the following article by Florent Appointaire to learn more about Azure Container Service: https://www.starwindsoftware.com/blog/azure-container-service-how-to-start-correctly or Azure Kubernetes Service (AKS) https://azure.microsoft.com/en-us/blog/introducing-azure-container-service-aks-managed-kubernetes-and-azure-container-registry-geo-replication/

Go to the Azure Portal, and click "Create a resource", then browse to "Containers" and click "Container Instances":

wp-image-9549

A new blade will appear to create the Container Instance. Enter the following information:

  • Container Name: Enter a friendly name for your Container Instance
  • Container Image Type: Depending your needs, but in my case, I want to use a public image from the Docker Hub.
  • Container Image: You must specify the URI or Docker Hub tag of the public image. For instance, you can use the "microsoft/aci-helloworld" image to run a very basic "Hello World!" within your Container.
  • Subscription: Select your Azure Subscription
  • Resource Group: Select an existing Resource Group or create a new one
  • Location: Select the location in which the Container Instance will be located

Once you are ready, click "Next" to configure your Container:

wp-image-9550

Here, you must configure the Container Instance:

  • OS Type: Depending your Container Image, you will select "Windows" or "Linux"
  • Number of cores and Memory: You can customize your Container Instance
  • Networking: If you want to expose your Container Instance on Internet, then select "Yes"
  • DNS Name Label: This is the friendly name you will use to reach your Container Instance
  • Port: By default, the port number will be 80. This port will be opened in order to access to your Container Instance.
  • Open Additional Ports: You can open additional ports but ports 80 and 443 are commonly used for containers.
  • Restart Policy: Select when your Container Instance should restart: "Always", "On failure" or "Never".
  • Environment variable: You can set some environment variables within the Container.
  • Command override: This is the first command to execute within the Container.

wp-image-9551

Once you are ready, you can click "OK" and wait until the deployment is finished

wp-image-9552

You may get the following deployment error during the process:

"DnsNameLabelAlreadyTaken",    "message": "The DNS name label 'mycontainer' in container group 'mycontainer' not available. Try using a different label."

Nothing critical, you just have to modify the DNS Name Label and rerun the wizard.

Ok, great the deployment is done, so let's check the duration. In my case, a very basic Container Instance took only 1 minute 36 seconds, which is awesome.

wp-image-9553

To access to your Container Instance, copy and paste the FQDN in your favorite browser

wp-image-9554

Done! The ACI image will display a nice welcome page as shown below:

wp-image-9555

Azure Container Instances Logs

When the deployment is done, you can check the logs, and then you will see the following steps about the deployment:

  • Step 1: Pulling image "microsoft/aci-helloworld"
  • Step 2: Successfully pulled image "microsoft/aci-helloworld"
  • Step 3: Created container with a specific ID
  • Step 4: Started container with the ID

You can also check the Container Logs by navigating to "Containers" and then click "Logs".You should see the HTTP request generated when you viewed the application in your browser.

wp-image-9556

ACI and Windows PowerShell

For those of you who want to use the command line to deploy a Container, you can use Windows PowerShell to achieve this task.

Firstly, create the resource group with the New-AzureRmResourceGroup cmdlet:

wp-image-9557

Then, wait a few seconds until the Container Instance is created:

wp-image-9558

Now, try to access to your Container using your web browser and you will see the IIS Welcome page:

wp-image-9559

Azure Container Instances and Azure Container Registry

To go further, keep in mind that you can push your own Container in ACI. To get a local container into Azure Container Instances, you need to put it into a private repository that can be accessed by Container Instances. You can use:

  • Docker Hub
  • Azure Container Registry (ACR)

If you want to use ACR, then go to the Azure Portal and Click "Create a resource", "Containers", "Container Registry":

wp-image-9560

Enter a friendly name for your Container Registry:

wp-image-9561

The Azure Container Registry is created and I can access to my ACR using the login server: "getcmd.azurecr.io" as shown below:

wp-image-9562

You must enable the "Admin user" mode in order to generate the password:

wp-image-9563

Before pushing and pulling container images, you must have a valid Container image on your machine. In my case, I will pull the ACI Demo image from Docker Hub:

wp-image-9564

Before pushing the image to the Azure Registry, I must tag the image with the ACR login server name:

wp-image-9565

Then, I need to log in to my Azure Container Registry. Here, I use the "Docker Login" command as shown below:

wp-image-9566

Now, I can push the custom image to my Azure Container Registry:

wp-image-9567

I can confirm that the image exists in my ACR:

wp-image-9568

I can deploy this image to a new WebApp, or I can use this image during the ACI wizard:

wp-image-9569

StarWind Virtual SAN eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows StarWind Virtual SAN to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses.

Learn more about ➡ StarWind Virtual SAN.

Conclusion

Thanks to this great Azure Service, you can easily deploy your Container into Azure for the following purposes:

  • Test
  • Development
  • Production

You can interact with Azure Container Instances using Azure Codes, go to the following page: https://azure.microsoft.com/en-us/resources/samples/?sort=0&term=aci. These code samples will help you to interact with Azure Services.

Thanks for reading!

Related materials:


----

Read in my feedly



Sent from my iPhone

No comments:

Post a Comment