Sunday, October 18, 2020

Store image to the Azure Container Registry (ACR)

Once the application is built, compiled and tested; and an application image is created and is verified to work on Kubernetes, the step to the AKS route is to store the application image to a container repository so that the image can be shared with others and accessible from any location for additional work. DockerHub and Azure Container Repository(ACR) are common examples of container registries. Since the focus of the post is Azure Kubernetes Service (AKS), I will illustrate the use of the ACR for repository. An Azure Container Registry is a Docker registry in the Azure cloud that can be used to store docker images. The ACR can be created in Azure portal as well using command line interface. 

This post is part of the post that discusses Azure Kubernetes Service (AKS) Deployment Recepes. I have discussed about how to setup development envionment in Set up development environment, and how to create docker image using a sample application in Create a Docker Image of an Application and the corresponding code can be downloaded from https://github.com/benktesh/LiveStreaming/tree/learnAKS. I also discussed verification of the deployment of sample application into local Kubernetes cluster in Deplyoing an application to Kubernetes. In this post, I am going to use a docker image and deploy the image to a local Kubernetes cluster. I will also illustrate how to interact with Kubectl - a command line interface of kubernetes. 

Interacting with Azure

In order to use Azure Container Registry (ACR), I need to have a valid account and subscription in the Azure. Once can visit Azure and create an account if needed.  

In order for me to interact with Azure remotely using PowerShell, I have to install Azure Cli. The instruction for installing Azure Cli is availabe at Install Azure CLI on Windows. To verify the status of Azure cli, I can run Az version command in the PowerShell window. 

I can login to Azure using Az login, which opens a browser to interactively login to Azure and upon successful login, the command window is populated with a message and list of subscriptions. 

Azure command az account list --output table can be used to list all the subscription. az account set --subscription [subscription id] command can be used to select a software where 'subscription' is the id of subscription. az account show --output table shows the currently selected account information.

Now that I have set the account and subscription, I am going to start creating a resource group named 'livestreaming' and in the 'eastus' locations.

Az group create -n livestreaming -l eastus

I intend put all the resources created under this resource. This appraoch helps me manage the resources better. The next step is to create and use the Azure Container Registry (ACR).

Azure Container Registry (ACR)

Command az acr create -n livestreaming -g livestreaming -l eastus --sku basic is used to create an Azure Container Registry named as 'livetreaming' in the resource group 'livestreaming' and in location eastus with a basic tier.


I can log into the created container using az acr login -n livestreaming

Once successfully logged in to the ACR, executing az acr list --output table  command displays the details of the acr. I am making a note of the login server information which currently is 'livestreaming.azurecr.io' and tag the docker image with the login server name and a version such as v1. This step helps me deploy the image to the ACR later.  

docker tag livestreaming:local livestreaming.azurecr.io/livestreaming:v1

With the above command, I added a tagged source livestreaming.local to 'livestreaming.azurecr.io/livestreaming:v1'.


Now I am all set to push the image to container registry by running a docker push command as below:

docker push livestreaming.azurecr.io/livestreaming:v1

Once the process is completed, I can verify the existence of image in the ACR by running the following azure command to list the respository items which shows the existence of livestreaming registery:

az acr repository list -n livestreaming -o table



Summary

In this recipe, I demonstrated how to interact with Azure and create container registry and use Docker to push a docker image to azure container registry using the . The process can be summarized as below:  
  • Log In to azure
  • Create resource group azure
  • Create container registry in the azure
  • Log-in to container registry
  • Tag the image to be eligible for azure container registry
  • Push the image to the container registry

No comments:

Post a Comment