Kubernetes: From Experimenting with Minikube to AKS (Part 3)

Raphael Gab-Momoh
Azure Nigeria Community Group
8 min readSep 22, 2022

This article aims to help readers eliminate the fear of getting started with Kubernetes. In part 1, we looked at leveraging Minikube to install a one-node cluster locally and we tested it with a sample deployment. In part2, we conducted more deployments so as to fully grasp the basics and performed as many K8s-related tasks as possible. In Part 3, we will build our application using visual studio, publish the image to Azure Container Registry, and use that image to deploy our AKS cluster in Azure. If you missed the previous articles, here is the link to Part1 and here is the link to Part2

What is Azure Kubernetes Service

Azure Kubernetes Service is a managed service that lets you quickly deploy and manage clusters. Azure takes care of critical health monitoring and maintenance. The Kubernetes master node is managed by Azure and we only get to manage the agent nodes. AKS is free, you only pay for agent nodes within your cluster and not for the master node.

Prerequisites

  1. Azure Account for creating the AKS clusters
  2. Docker Community Edition
  3. Powershell in Azure portal
  4. Visual Studio 2019/2022

Step 1: Create a Kubernetes Application in Visual Studio

create a new project

Next, let us create a container application for Kubernetes, you can just type Kubernetes in the search bar so that we can use the container application template in visual studio to help make things easier. Hit the next button after that

container Kubernetes application template

After hitting the following button, you can choose a name for your application and create it. In this particular case, we choose the name AzureNaija Kubernetes

configuring your application

Next, we choose the type of application we want to build as seen below

web application

Next, click on create and the process will generate a YAML & Dockerfile for the Kubernetes application that we are building . If we click on the highlighted red rectangular azds.yaml file, we will see that it will bring all the details about the yaml file as shown below

azds.yaml file

The Dockerfile is shown below as well

docker file

Step2: Deploy the application on Azure Container Registry

Create a container registry in Azure first, after that return to visual studio and right-click on the name of the application, and publish the application to the container registry created.

create a container registry
Azure Container Registry
Publish to container registry

When we click on Azure Container Registry, you will be required to sign into your azure account. Also, notice the container registry created earlier and its resource group gets shown to us as highlighted in the image below

Sign in to Azure Portal

Following each of the prompts so as to successfully publish the application onto the container registry we created in the Azure portal. Please note that you will need to install docker desktop for the process to be completed successfully, this is because the application that we built is based on a container file.

published

We can also check Docker Desktop to verify

results are shown on Docker Desktop

If we check the repository under services, we will see that the application azurenaijakubernetes has actually been published to Azure with the latest tag.

repo

Now that we have successfully published our application on Azure Container Registry, we can proceed to build our cluster. So we already have a resource group called aznaija, the repo name is azurenaijak8s. The name of the cluster we are creating will be called myAksCluster. We can run this in cloud shell to create our cluster using the command below:

az aks create --resource-group aznaija --name myAksCluster --node-count 1 --generate-ssh-keys --attach-acr azurenaijak8s
cluster creation command

Output

PS /home/raphael> az aks create --resource-group aznaija --name myAksCluster --node-count 1 --generate-ssh-keys --attach-acr azurenaijak8s
SSH key files '/home/raphael/.ssh/id_rsa' and '/home/raphael/.ssh/id_rsa.pub' have been generated under ~/.ssh to allow SSH access to the VM. If using machines without permanent storage like Azure Cloud Shell without an attached file share, back up your keys to a safe location
Resource provider 'Microsoft.ContainerService' used by this operation is not registered. We are registering for you.
Registration succeeded.
AAD role propagation done[############################################] 100.0000%{
"aadProfile": null,
"addonProfiles": null,
"agentPoolProfiles": [
{
"availabilityZones": null,
"count": 1,
"creationData": null,
"currentOrchestratorVersion": "1.23.8",
"enableAutoScaling": false,
"enableEncryptionAtHost": false,
"enableFips": false,
"enableNodePublicIp": false,
"enableUltraSsd": false,
"gpuInstanceProfile": null,
"hostGroupId": null,
"kubeletConfig": null,
"kubeletDiskType": "OS",
"linuxOsConfig": null,
"maxCount": null,
"maxPods": 110,
"minCount": null,
"mode": "System",
"name": "nodepool1",
"nodeImageVersion": "AKSUbuntu-1804gen2containerd-2022.08.29",
"nodeLabels": null,
"nodePublicIpPrefixId": null,
"nodeTaints": null,
"orchestratorVersion": "1.23.8",
"osDiskSizeGb": 128,
"osDiskType": "Managed",
"osSku": "Ubuntu",
"osType": "Linux",
"podSubnetId": null,
"powerState": {
"code": "Running"
},
"provisioningState": "Succeeded",
"proximityPlacementGroupId": null,
"scaleDownMode": null,
"scaleSetEvictionPolicy": null,
"scaleSetPriority": null,
"spotMaxPrice": null,
"tags": null,
"type": "VirtualMachineScaleSets",
"upgradeSettings": {
"maxSurge": null
},
"vmSize": "Standard_DS2_v2",
"vnetSubnetId": null,
"workloadRuntime": null
}
],
"apiServerAccessProfile": null,
"autoScalerProfile": null,
"autoUpgradeProfile": null,
"azurePortalFqdn": "myaksclust-aznaija-3c914a-fa31a26f.portal.hcp.eastus.azmk8s.io",
"currentKubernetesVersion": "1.23.8",
"disableLocalAccounts": false,
"diskEncryptionSetId": null,
"dnsPrefix": "myAksClust-aznaija-3c914a",
"enablePodSecurityPolicy": null,
"enableRbac": true,
"extendedLocation": null,
"fqdn": "myaksclust-aznaija-3c914a-fa31a26f.hcp.eastus.azmk8s.io",
"fqdnSubdomain": null,
"httpProxyConfig": null,
"id": "/subscriptions/3c914a49-248d-4902-bfe4-3d4214320cbf/resourcegroups/aznaija/providers/Microsoft.ContainerService/managedClusters/myAksCluster",
"identity": {
"principalId": "310e2024-887b-4a70-a1d7-29a6c7d914c5",
"tenantId": "21cef452-6ccc-4171-9420-b34ecb234499",
"type": "SystemAssigned",
"userAssignedIdentities": null
},
"identityProfile": {
"kubeletidentity": {
"clientId": "38e90461-9652-4817-af77-a4cbf2138949",
"objectId": "34b5cc38-caa7-4882-8739-ac7c8e13c5a3",
"resourceId": "/subscriptions/3c914a49-248d-4902-bfe4-3d4214320cbf/resourcegroups/MC_aznaija_myAksCluster_eastus/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myAksCluster-agentpool"
}
},
"kubernetesVersion": "1.23.8",
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
--------------------------------------------------------------------

From the image below, we can see that our AKS cluster is running

running

We can see from the screenshot below that clicking on the connect button at the top of the cluster overview page will help us connect to our cluster.

connect

Azure is very generous, every component has been deployed for us. We can see clearly, the controller manager, Kube-proxy and others necessary for our application to run smoothly. Again, if we run the get node command, it shows us the agent pool.

Node

Step 3: Deployment of the Application

We have the name of our application from visual studio, azurenaijakubernetes, we also have our application image hosted on the Azure container registry and the image is https://azurenaijak8s.azurecr.io.azurenaijakubernetes:latest. So, with these, we can use a basic deployment template. You can use a basic template from the Kubernetes documentation site here. Replace the name in the template with the one for our application. and just make sure that for the spec section, the container has the name of the application and the image. To begin with, you need to use a text editor like vi to create the deployment file. You can do so with the command:

vi azurenaija-deployment.yamlapiVersion: apps/v1
kind: Deployment
metadata:
name:azurenaijakubernetes
labels:
app: azurenaijakubernetes
spec:
replicas: 1
selector:
matchLabels:
app:azurenaijakubernetes
template:
metadata:
labels:
app: azurenaijakubernetes
spec:
containers:
- name: azurenaijakubernetes
-image:azurenaijak8s.azurecr.io/azurenaijakubernetes:latest
ports:
- containerPort: 80
protocol: TCP

Press the escape button on your keyboard, shift : and wq to exit vi editor and run the following command to create the deployment from the file

kubectl create -f azurenaija-deployment.yaml
deployment created

Task 1: View the deployment

kubectl get deployment
View deployment

As we can see, it’s not ready but if we check back, it definitely will show that it is ready. So check back, this might take another 3 minutes or more.

Task 2: Describe the deployment

kubectl describe deployment azurenaijakubernetes

A describe command will help show more details about the processes

describe deployment

Task 3: Get Service type

There needs to be communication between the application and any other process and service that makes discoverability possible. We can also use the shorthand form svc instead of service as seen in the screenshot below

kubectl get service
service

Task4: Get the Endpoint

The Endpoint is provided by kubelet and Kube-proxy. Take note of the current endpoint IP we can choose to use the short for ep instead of endpoint

Kubectl get ep

Task5: Show the deployment in yaml format

we can do so with the command, if there is more than one deployment in our production environment, you will need to be specific by adding the name of the particular deployment but since we have just one, we will just use the command below:

kubectl get deployment -o yaml
o yaml

Task 6: Scale the deployment

At the moment, we have about 3 replicas, if we decide to scale the replicas to 10, we can use the command below

kubectl scale deployment --replica=10
scaled

Task 7: Clean up

We can do this by using the command shown below:

kubectl delete deployment azurenaijakubernetes
delete

Summary

We have come to the end of our three parts series from experimenting with Minikube to AKS, we can clearly see that all the things that we were able to do in Minikube can be done in AKS but it’s just that Minikube is for learning and experimentation, while AKS is for production purposes. You can follow all the steps and be up and running with Kubernetes on the Azure Platform. Thank you for reading.

--

--

Raphael Gab-Momoh
Azure Nigeria Community Group

Experienced Cloud Engineer with a demonstrated history of working in the information technology and services industry.