Azure Hands-On - Deploying a Web Application with AKS and ACR
Azure Learning Path for Cloud and DevOps Engineers
Table of contents
- 📝Introduction
- 📝Log in to the Azure Management Console
- 📝Prerequisites:
- 📝Setting an Azure Storage Account to Load Bash or PowerShell
- 📝Set up your Azure AKS environment
- 📝Create a Resource Group
- 📝 Create an Azure Container Registry (ACR)
- 📝 Build and Push Docker Image to ACR
- 📝Create an AKS Cluster
- 📝 Connect to AKS Cluster
- 📝Deploy the Application to AKS
📝Introduction
In this hands-on lab, we walked through deploying a web application using Azure AKS and ACR.
📝Log in to the Azure Management Console
Using your credentials, make sure you're using the right Region. In my case, I am using the region France Central
in my Cloud Playground Sandbox.
📌Note: You can also use the VSCode tool or from your local Terminal to connect to Azure CLI
More information on how to set it up is at the link.
📝Prerequisites:
Update to PowerShell 5.1, if needed.
Install .NET Framework 4.7.2 or later.
Visual Code
Web Browser (Chrome, Edge)
Azure CLI installed
Azure subscription
Docker installed
📝Setting an Azure Storage Account to Load Bash or PowerShell
- Click the Cloud Shell icon
(>_)
at the top of the page.
- Click PowerShell.
- Click Show Advanced Settings. Use the combo box under Cloud Shell region to select the Region. Under Resource Group and Storage account(It's a globally unique name), enter a name for both. In the box under File Share, enter a name. Click ***Create storage (***if you don't have any yet).
📝Set up your Azure AKS environment
Login to Azure:
az login
Set the subscription (if you have multiple):
az account set subscription <your-subscription-id>
📝Create a Resource Group
az group create --resource-group <nameResourceGroup> --location <region>
📝 Create an Azure Container Registry (ACR)
az acr create --resource-group <nameResourceGroup> --name <nameContainerRegistry> --sku Basic
📝 Build and Push Docker Image to ACR
Login to ACR:
az acr login --name <nameContainerRegistry>
Create a Dockerfile
Create an
Dockerfile
in-your-project directory. Here’s an exampleDockerfile
for a simple Nginx HTML webpage:FROM nginx:alpine COPY index.html /usr/share/nginx/html
Build Docker image:
docker build -t <nameapp>:v1 .
Tag the Docker image:
docker tag <nameapp>:v1 <nameContainerRegistry>.azurecr.io/<nameapp>:v1
Push the Docker image to ACR:
docker push <nameContainerRegistry>.azurecr.io/<nameapp>:v1
📝Create an AKS Cluster
az aks create -g <nameResourceGroup> -n <nameAKSCluster> --node-count 1 --generate-ssh-keys --attach-acr demoacrx1
📝 Connect to AKS Cluster
Use the Azure Cloud Shell to check your AKS Cluster resources, by following the steps below:
Go to Azure Dashboard, and click on the Resource Group created for this Lab, looking for your AKS Cluster resource.
On the Overview tab, click on Connect to your AKS Cluster.
A new window will be opened, so you only need to open the Azure CLI and run the following commands:
az login
az account set subscription <your-subscription-id>
az aks get-credentials -g <nameRersourceGroup> -n <nameAKSCluster> --overwrite-existing
- After that, you can run some Kubectl commands to check the default AKS Cluster resources.
📝Deploy the Application to AKS
Create a Kubernetes deployment yaml file (
deployment.yaml
):apiVersion: apps/v1 kind: Deployment metadata: name: demoapp spec: replicas: 2 selector: matchLabels: app: demoapp template: metadata: labels: app: demoapp spec: containers: - name: demoapp image: demoacrx1.azurecr.io/demoapp:v1 ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: demoapp spec: type: LoadBalancer ports: - port: 80 targetPort: 8080 selector: app: demoapp
Apply the deployment:
kubectl apply -f deployment.yaml kubectl exec -it <namepod> -- curl localhost
Checking the resources created and running into the AKS Cluster:
kubectl get pods kubectl get svc kubectl get deployment kubectl describe pod <namepod>
To check if the containers are loading correctly the Nginx HTML webpage, run the following command:
kubectl exec -it <namepod> -- curl localhost
📌Note - At the end of each hands-on Lab, always clean up all resources previously created to avoid being charged.
Congratulations — you have completed this hands-on lab covering the basics of Deploying a Web Application with Azure AKS and ACR.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on Cloud&DevOpsLearn and LinkedIn, franciscojblsouza