Sunday, May 8, 2022

Azure Container Registry, Container Instance

 Azure Container Registry

It allows you to build, store and manage container images and artifacts in private registry for all types of container deployments.


Lab

Step 1: Create a virtual machine in Azure of ubuntu type to connect with Azure Container registry.

Step 2: Install Docker on the above VM.

             apt update

             apt install docker.io -y

Step 3: Create a container registry by searching container registries on Azure portal. Registry name I am using myreg100

Step 4: Install Azure CLI on your vm and push docker image to azure registry.

Install Azure CLI

curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor |  sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null



AZ_REPO=$(lsb_release -cs)

echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list

sudo apt-get update

sudo apt-get install azure-cli

Login to Azure using CLI (After running this command you need to follow the instruction to connect with Azure CLI)

sudo az login

Log in to your container registry

sudo az acr login --name myreg100

Pull a Docker image and push it docker registry      

sudo docker pull nginx
sudo docker tag nginx myreg100.azurecr.io/mynginx

Push the image to Azure Container registry and once pushed then check the container registry ---> Repositories and you will find mynginx image is available.

sudo docker push myreg100.azurecr.io/mynginx

Container Instance

To deploy an application in azure as container you can use Container instance.

Step 0: Goto Container registry and select your repository (myreg100) and select Access keys and enabled for Admin user

Step 1: Go to Azure portal and search for the container instance.

           Select container registry image :- myreg100

           Open Port no: 80

Step 2: Once Container is created it will give you the Public IP address and use this IP address on the browser you will be able to see nginx web page.

AKS (Azure Kubernetes Cluster )

To Deploy Containers on AKS we follow the below steps

Step 1: Search for Kubernetes service on the Azure portal.

Step 2: Create Kubernetes cluster by using container image - myreg100

            It will take around 5-10 mins to create the cluster

Step 3: Once Cluster is created then Select Workloads--> Create-->ADD Yaml for deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-app
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      - name: nginx-container
        image: myreg100.azurecr.io/mynginx
        ports:
        - containerPort: 80


Step4: Add another yaml file for services

apiVersion: v1
kind: Service
metadata:
  name: my-service
  labels:
    app: nginx-app
spec:
  selector:
    app: nginx-app
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 80

Step 5: In Services and Ingress you will find an External IP for your deployment use that IP address to access the deployment.










0 comments:

Post a Comment