Orchestrating Applications with Azure Kubernetes Service (AKS)

This tutorial guides you through the fundamental steps of orchestrating containerized applications using Azure Kubernetes Service (AKS). AKS simplifies deploying, managing, and scaling containerized applications using Kubernetes on Azure.

Prerequisites

Before you begin, ensure you have the following:

Creating an AKS Cluster

First, let's create a basic AKS cluster. Open your terminal or Azure Cloud Shell and run the following commands:


az group create --name myAKSResourceGroup --location eastus
az aks create --resource-group myAKSResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
            

This command will create a resource group named myAKSResourceGroup and then create an AKS cluster named myAKSCluster with one node. The --enable-addons monitoring flag includes Azure Monitor for containers.

Once the cluster is created, connect kubectl to your cluster:


az aks get-credentials --resource-group myAKSResourceGroup --name myAKSCluster
            

Verify the connection by listing the nodes in your cluster:


kubectl get nodes
            

Deploying a Sample Application

Now, let's deploy a simple multi-container application to your AKS cluster. We'll use a sample application that consists of a frontend web application and a backend API.

Create a Kubernetes deployment and service for the frontend:


# Create a deployment
kubectl create deployment frontend --image=mcr.microsoft.com/azuredocs/azure-vote-front:v1

# Expose the deployment as a service
kubectl create service clusterip frontend --tcp=80:80
            

Create a Kubernetes deployment and service for the backend API:


# Create a deployment
kubectl create deployment backend --image=mcr.microsoft.com/azuredocs/azure-vote-back:v1

# Expose the deployment as a service
kubectl create service clusterip backend --tcp=8080:8080
            

Now, let's create an Ingress resource to expose the frontend application to the internet. This requires the Nginx Ingress Controller to be installed on your AKS cluster. If it's not already installed, you can install it using Helm.

Note: If you haven't installed Helm, refer to the Helm installation guide.


# Add the ingress-nginx repository
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

# Install the ingress-nginx controller
helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace
            

Once the Ingress Controller is running, create an Ingress resource:


cat <

Retrieve the external IP address for your Ingress controller:


kubectl get service nginx-ingress-ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
            

Open this IP address in your web browser to see your deployed application.

Scaling the Application

AKS makes scaling your applications straightforward. You can scale the number of pods for a deployment or use Horizontal Pod Autoscaler (HPA) to automatically scale based on resource utilization.

To manually scale the frontend deployment:


kubectl scale deployment frontend --replicas=3
            

To view the updated number of pods:


kubectl get pods
            

Tip: For automatic scaling, explore the Horizontal Pod Autoscaler in Kubernetes.

Monitoring AKS

Monitoring is crucial for understanding the health and performance of your cluster and applications. AKS integrates with Azure Monitor for containers.

You can view your cluster's performance metrics, logs, and alerts directly within the Azure portal by navigating to your AKS resource and selecting "Insights" under the "Monitoring" section.

You can also use kubectl to view pod status and resource utilization:


kubectl top pods
kubectl top nodes
            

Advanced Topics

This tutorial covered the basics. For more advanced scenarios, consider exploring:

Important: Remember to clean up your resources after completing the tutorial to avoid incurring unnecessary Azure charges. You can delete the resource group using:


az group delete --name myAKSResourceGroup --yes --no-wait