Hands on Azure Container Registry and Azure Kubernetes Services – practical from scratch.
In this 2 step series (in continuation with the deploy-app-azure-free) I am targeting to:
Create, build, upload and store an image to ACR.
Orchestrate using AKS
To work on containers, I have to install AZURE CLI which supports various commands in this aspect.
Downloaded it from https://learn.microsoft.com/en-us/cli/azure/install-azure-cli#install
Downloaded MSI for windows and started installing.
Verified if the CLI is now able to run AZURE commands.
AND it was successful.
Run the CART app locally.
I want to run the same code in AKS i.e. Azure Kubernetes Service
To do that I need to push this code as an image in the container registry.
And to work with containers, I have to install one more extension in VSCode; named ‘Docker’ created by Microsoft.
NOTE: Docker is now a day’s de-facto standard for containers but there are others as well.
Clicked ‘Install’
Docker extension installed successfully on my local VSCode.
Before proceed, trying to throw some light on few IMPORTANT Docker aspects:
- What is a container?
A software package that runs in any environment.
- Why do we need Container/s?
When we share a software to any other environment, it may result in ‘It works on that machine but not my machine’. Container solves this problem of replicating the required environment for software to run.
- Why not VM?
It's heavy, time taking and at times results in issues.
- What is DOCKER?
Docker is a tool that can package containers that run reliably in any environment.
- Why Docker?
It's lightweight, faster and reliable.
Three MAJOR fundamental concepts about DOCKER in short
- Dockerfile - a set of instruction in a file format that contains the
code repository path that needs to be containerized along with
the dependencies AND
the configuration.
In short, a Dockerfile is a BLUEPRINT or a DNA that tells DOCKER ‘How to build an image?’
Image – is a SNAPSHOT of your software.
It contains all of the software dependencies with details till operating system level. An IMAGE is immutable (cannot be changed).
Container – is a running software / process.
NOW, I need to containerize my CART app.
I am going to build an image in Azure Container Registry.
To do that, let me navigate to AZURE PORTAL.
Search for ‘Registry’
Click on ‘Container registries’
Hit ‘Create’ or any of the buttons highlighted below SS.
For basics information:
Used ‘readit-app-rg’ as a resource group.
The name for my ACR is ‘readitnitin’. This should be unique.
Location – will use the nearest to my location.
Pricing plan will be ‘Basic’
It offered me ‘Standard’ pricing plan but the storage offered in ‘Basic’ is enough for my task.
Also, check the cost for BASIC and STANDARD on the ‘More pricing info’ link.
NOTE the pricing differences.
Back to ‘Create container registry’
Clicked the ‘Review and create’ button.
Clicked on ‘Create’ button
NOTE that here we can see, its offering the code to automate this part on click of ‘Download a template for automation’ URL.
The deployment for the ACR is complete.
Clicked on ‘Go to resource’ to validate the same as I opted.
And navigated to the ‘Capabilities’ tab – where I could see the features I can perform with this package.
To enable my local VSCode to access this registry and push images to, I have to enable the same from AZURE PORTAL.
To do so, EXPAND ‘Settings’ and clicked on ‘Access Keys’
Clicked on the check box for ‘Admin user’
And that created the ‘Admin user’ access successfully.
With this step success, I have my ACR up and running.
AND I can now use this to store docker images at this location.
For further steps, go to VSCode.
Clicked on the ‘Docker’ icon from the extensions list.
Clicked on ‘Connect Registry’
Then in the search bar, suggested list; selected ‘Azure’
And my ACR is connected with my VSCode
Expanded the ‘Azure’ from the REGISTRIES pane.
VSCode asked me for permission.
Clicked on ‘Allow’.
And, asked me to select an account for further processing.
I selected the account that is mapped with my current ACR subscription.
Then I could see my subscription and registry name listed under.
Now that my intended registry is connected, I will build and push the image to the AZURE CONTAINER REGISTRY.
To do that, right clicked on ‘Dockerfile’ and
Selected ‘Build Image in Azure’ from the option list.
It asked to tag image
Updated tag value and hit enter.
Selected ‘Azure’ from the options listed.
Selected subscription to be used.
Selected REGISTRY name
Selected base OS as LINUX
It started the process but encountered an error.
I have to login to azure account using ‘Terminal’
Enter ‘az login’ and hit enter.
Gave error again.
So I restarted the VSCode and did the same steps. And this time it went as expected.
Selected the account and clicked continue.
Facing error while connecting to account.
Learning from mistakes
BELOW SS has important guidance which I used to connect dots, which is not mentioned in any ‘pre-requisite/s’ while we work on ACR.
You have to install Docker on your local to run ‘docker’ commands.
The same is asked from containers and images warning messages.
NOTE – Observed, VSCode had prompted me to ‘install docker’ and I ignored it. Tools are smarter ☺
Troubleshooting.
Installed Docker desktop from Install Docker Desktop on Windows | Docker Docs
NOTE – Installing docker has some system requirements. If your system meets the requirement, you are good to go.
VSCode Docker and Images status post Docker installation.
Tried connecting the ACR again and it was successful with command ‘az login –tenant <tenant-ID>
Hit enter as I had no changes.
The connection was successful.
Tried with ‘Build Image in Azure’ and followed the steps from ‘Now that my intended registry is connected, I will build and push the image to AZURE CONTAINER REGISTRY.’
The build and push image to ACR is successful.
Refreshed the VSCode Registries to see the latest changes – it reflected.
Then went to Azure portal > repositories ‘readitnitin’ > Services section and clicked ‘Repositories’
The ‘cart’ image is reflected with the tags created.
Clicked on ‘cart’ and it displayed the manifest it used by ACR to upload and store the image.
Stay tuned for AKS part.
Subscribe to my newsletter
Read articles from Nitin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nitin
Nitin
A Seasoned gate keeper for software quality (Manual / Automation (Web + Mobile native + API) / Performance test) with 13 years of experience, An automation🤖 lover and a continuous📚 learner. A test automation geek and a DevOps engineer using and exploring cloud☁️. Looking for opportunities in Cloud DevOps for mutual growth. (Working remotely since last 5 years with teams in Europe / USA and Canada)