Blogs • X-Centric IT Solutions

Creating and Managing Azure Container Instances

Written by Justin Knash | 04/14/2023

A Comprehensive Guide to Deploying and Orchestrating Containers using Azure Services

Introduction

As the adoption of containerization accelerates, developers and organAzure Container Instances offers an effortless way to run and manage containers in the Azure cloud environment, without requiring the user to maintain the infrastructure. Organizations worldwide are turning to Microsoft Azure to build, deploy, and manage containerized applications. Azure offers a range of services to help you manage containers, including Azure Container Instances (ACI), Azure Kubernetes Service (AKS), and Azure Container Registry (ACR). In this blog post, we will explore these services and walk you through the process of creating, deploying, and managing containers in Azure.

Azure Container Instances (ACI)

Azure Container Instances (ACI) is a serverless container orchestration service that allows you to run containers in Azure without managing the underlying infrastructure. ACI is ideal for scenarios where you need a fast, cost-effective solution for deploying single-container applications.

Creating and deploying a container using ACI:

1. Prepare your container image: Before deploying a container, you must create a container image, which is a snapshot of the application and its dependencies. Use Docker to create the image and store it in a container registry, such as Azure Container Registry or Docker Hub.

2. Authenticate with Azure: Sign in to the Azure Portal and open the Azure Cloud Shell, or use the Azure CLI from your local machine. Make sure you have the necessary permissions to create and manage resources in your Azure subscription.

3. Create a resource group: In the Azure Portal or Azure CLI, create a resource group to organize and manage your container resources.

az group create --name myResourceGroup --location eastus

4. Deploy the container: Use the az container create command to deploy your container in the specified resource group. Replace <container_registry>/<image_name> with the path to your container image in the registry.

az container create \
--resource-group myResourceGroup \ 
--name mycontainer \
--image <container_registry>/<image_name> \
--restart-policy OnFailure

5. Monitor the container: Use the az container show command to view the container's details and status.

az container show --resource-group myResourceGroup --name mycontainer

6. Access container logs: Use the az container logs command to view the logs of your container.

az container logs --resource-group myResourceGroup --name mycontainer

Azure Kubernetes Service (AKS)

Azure Kubernetes Service (AKS) is a managed Kubernetes service that simplifies the deployment, management, and scaling of containerized applications. AKS is ideal for scenarios where you need to manage and orchestrate multi-container applications.

Creating and deploying a container using AKS:

1. Prepare your container image: Similar to ACI, you must create a container image using Docker and store it in a container registry.

2. Authenticate with Azure: Sign in to the Azure Portal and open the Azure Cloud Shell, or use the Azure CLI from your local machine.

3. Create a resource group: Create a resource group to organize and manage your AKS resources.

az group create --name myResourceGroup --location eastus

4. Create an AKS cluster: Use the az aks create command to create a new AKS cluster. Replace <your_ssh_key> with your public SSH key.

az aks create \ 
--resource-group myResourceGroup \
--name myAKSCluster \
--node-count 1 \
--ssh-key-value <your_ssh_key>

5. Connect to the cluster: Use the az aks get-credentials command to configure the kubectl command-line tool to connect to your AKS cluster

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

6. Deploy the container: Create a Kubernetes manifest file (e.g., deployment.yaml) that describes your containerized application, including the image location, resource requirements, and desired number of replicas. Then, use the kubectl apply command to deploy the container.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mycontainer
  spec:
    replicas: 1
  selector:
    matchLabels:
      app: mycontainer
        template:
          metadata:
            labels:
              app: mycontainer
  spec:
    containers:
      - name: mycontainer
    image: <container_registry>/<image_name>
    ports:
      - containerPort: 80
kubectl apply -f deployment.yaml

7. Monitor the container: Use the kubectl get command to view the status of your deployed container and other related resources.

kubectl get deployments
kubectl get pods

8. Access container logs: Use the kubectl logs command to view the logs of your container.

kubectl logs <pod_name>

Azure Container Registry (ACR)

Azure Container Registry (ACR) is a managed Docker registry service that allows you to store and manage your private container images in Azure. ACR integrates seamlessly with ACI, AKS, and other Azure services, enabling secure and efficient container image deployment.

Creating and managing a container registry in ACR:

1. Authenticate with Azure: Sign in to the Azure Portal and open the Azure Cloud Shell, or use the Azure CLI from your local machine.

2. Create a resource group: Create a resource group to organize and manage your ACR resources.

az group create --name myResourceGroup --location eastus

3. Create a container registry: Use the az acr create command to create a new container registry. Replace <registry_name> with a unique name for your registry.

az acr create --resource-group myResourceGroup --name <registry_name> --sku Basic

4. Authenticate with the registry: Use the az acr login command to authenticate your Docker client with the ACR registry.

az acr login --name <registry_name>

5. Push a container image to ACR: Tag your local container image with the registry's login server and push the image to the registry.

docker tag <local_image_name> <registry_name>.azurecr.io/<image_name>
docker push <registry_name>.azurecr.io/<image_name>

6. Manage container images: Use the az acr command-line tool to list, delete, and manage container images in your registry.

az acr repository list --name <registry_name>
az acr repository show-tags --name <registry_name> --repository <image_name>
az acr repository delete --name <registry_name> --image <image_name>:<tag

Conclusion

Azure provides a comprehensive set of services for creating, deploying, and managing containerized applications, including Azure Container Instances, Azure Kubernetes Service, and Azure Container Registry. By understanding the features and capabilities of these services, you can leverage the power of Azure to streamline your container management processes, reduce operational overhead, and ensure that your applications run smoothly and securely in the cloud.

As the world of application development continues to evolve, containerization is becoming the industry standard for deploying and managing software. By harnessing the power of Azure's container orchestration services, you can accelerate your application development and deployment workflows, while optimizing resource utilization

Ready to revolutionize your business with Azure Compute Services? Don't wait! Get started now and experience unmatched scalability and performance. Click here to begin your cloud journey.