Deploy an application for AKS

Rebai Hamida
4 min readMay 20, 2021

--

Introduction

“Azure Kubernetes Service (AKS) simplifies deploying a managed Kubernetes cluster in Azure by offloading the operational overhead to Azure. As a hosted Kubernetes service, Azure handles critical tasks, like health monitoring and maintenance. Since Kubernetes masters are managed by Azure, you only manage and maintain the agent nodes. Thus, AKS is free; you only pay for the agent nodes within your clusters, not for the masters.”

for more details: Introduction to Azure Kubernetes Service — Azure Kubernetes Service | Microsoft Docs

Prerequisite

  • Azure account: you should be able to create an AKS Cluster.
  • Docker Community Edition & Visual Studio 2019

Create Kubernetes application in Visual Studio 2019

To create a new application using Visual Studio, we open it, select “Create a new project” , we tape Kubernetes in the search bar to select Container Application for Kubernetes. This template is used to create ASP.NET Core Web service with Docker container support running in Kubernetes.

Deploy the application on Azure Container Registry

We build our application on release mode after we can deploy it using visual studio by publishing it on existing container or creating a new container registry.

Create AKS cluster using Azure CLI

Create an AKS cluster using the az aks create command. The following example creates a cluster named myAKSCluster with one node:

az aks create — resource-group aksgr — name myAKSCluster — node-count 1 — generate-ssh-keys — attach-acr aksprojectcontainer

Create AKS Cluster using Azure Portal

We open Azure Portal, we click on Create a resource, we scroll up to select Kubernetes and we click on create.

You need to fill the project details, you will select your subscription account, after you select your resource group or you can create new one.

Next, you will fill Cluster details, like Kubernetes cluster name, the Azure region into which the cluster should be deployed, Availability Zones (1,2, 3 zones), the version of Kubernetes that should be used for this cluster, we are always able to upgrade this version after the creation of the cluster, we select the node size and the number of nodes.

We can add more node pool or update the cluster infrastructure authentication, in networking tab, we can select the network configuration (Kebenet or Azure CNI), define the traffic routing or more, in integration tab, we will select our container deployed in Azure Container Registry, so we can select it or create a new, in addition to the CPU and memory metrics included in AKS by default, you can enable Container Insights for more comprehensive data on the overall performance and health of your cluster. Billing is based on data ingestion and retention settings, we have also, azure policy to apply at-scale enforcements and safeguards for aks. And in the end, we click on Review + create button.

Deploy an Azure Kubernetes Service cluster and run an application using the Azure CLI

We have to create A Kubernetes manifest file to be able to deploy the application in our cluster created before, such as which container images to run.

1- Open CloudShell My Dashboard — Microsoft Azure and connect to your cluster as bellow:

az account set — subscription yoursubscription

az aks get-credentials — resource-group aksgr — name myAKSCluster

You can find these commands when you open Azure Portal and your cluster:

2- Create an empty file called: azure-demo-deployment.yaml

3- Copy this content to the empty file created, we will describe it after.

apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-kubernetes-deployment
spec:
selector:
matchLabels:
app: demo-kubernetes-pod
replicas: 1
template:
metadata:
labels:
app: demo-kubernetes-pod
spec:
containers:
— name: aksprojectcontainer
image: aksprojectcontainer.azurecr.io/aksproject:latest
ports:
— containerPort: 80

4- Run the application and deploy it in the cluster using the kubectl apply command and specify the name of your YAML manifest.

kubectl apply -f azure-demo-deployment.yaml

And now we will use kubectl get deployments to verify if the deployment was created or not.

When the application runs, a Kubernetes service exposes the application front end to the internet. This process can take a few minutes to complete.

5- we will use kubectl get service command with the --watch argument.

kubectl get service demo-kubernetes-deployment — watch

Debug your application using Bridge to Kubernetes

We can configure Bridget to Kubernetes to compile, debug and run your application in your AKS Cluster.

--

--

Rebai Hamida
Rebai Hamida

Written by Rebai Hamida

Senior Cloud Application Architect, Microsoft MVP in Developer Technologies, MCT, Technical writer, Speaker