Global Azure May 2022

Tech Talks delivered by Wriju on Azure, Programming and DevOps

Global Azure May 2022

Demo steps and commands. This is just for idea. For tested script please use: Azure Script

Same Nginx Image as WebApp used by kubectl

Nginx is a web app which can be used for demonstration purpose.

docker.io/library/nginx

Docker Steps

Below are the steps for local docker

Check if docker is running by

docker ps

If the above is not working and the error is "Docker daemon is not running" then

sudo service docker start

To run the nginx

-d will ensure that it runs in the background. Becasue without it the nginx will hold the prompt.

docker run -d docker.io/library/nginx

To confirm it is running use

docker ps

To enter inside the running container, (to use name either give a proper name or use the name auto generated by docker.

docker exec -it fc20b0420169 /bin/sh

Then in the tty run

curl http://localhost

If the page is showing then it is running inside the docker as a container.

Azure Container Registry (ACR)

Create the ACR via either portal or script. Portal is good for demo to clear the concept/

Then from local shell push it to Azure. Follow the below steps/

Push to ACR

Create ACR

Create in Portal best for demo.

Azure CLI

acr=wgacr2
az acr create -g $g -n $acr --admin-enabled=true --sku=basic

First login to the ACR

docker login -u $acr -p SuperSecret $acr.azurecr.io

Download the nginx image to local machine

docker pull nginx

Then re-tag it based on the ACR. If the name of the ACR is

wgacr then tag it as wgacr.azurecr.io/nginx:latest

To verify if the image is available locally and note the image_id

docker images

Then re-tag it as per the acr created above

image=$acr.azurecr.io/nginx:latest
docker tag IMAGE_ID $image

Push the image to ACR

docker push $image

Azure Container Instance (ACI)

Create a new ACI pointing to the ACR we have uploaded the nginx to through Portal. Again showing it in Portal is best for demo. But actually we must automate it.

From the overview of ACI get the public IP and open it in browser. You will see the landing page of Nginx.

Azure CLI (sample)

You may also login to the Shell for ACR

az acr login -n $acr

Below will create ACI but prompt for the registry username and password.

az container create -g $g -n nginx420 --image=$image --ip-address=Public 

To avoid that, you may pass two additional parameters

az container create -g $g -n nginx420 --image=$image --ip-address=Public --registry-username=$acr --registry-password=PASSWORD

Azure App Service (Container)

To create a Azure App Service with container use portal.

# Create App Service Plan (Linux)
plan=asPlan420

az appservice plan create -g $g -n $plan --is-linux --sku B2


az webapp create -g $g -n wgwebapp420 -p $plan -i=$image -s wgacr -w PASSWORD

Azure Kubernetes Service (AKS)

Create

Create AKS cluster from Azure Portal. However, recommended is to use the Azure CLI.

Deployment

alias k=kubectl

k get nodes

k create deploy nginx --image=$image

k expose deploy nginx --port=80 --type=LoadBalancer

k get svc 

curl http:Public-Ip of the service