Azure Kubernetes Service (AKS) Deployment: A Step-by-Step Guide

Azure Kubernetes Service (AKS) Deployment: A Step-by-Step Guide

Cloud-native technologies have revolutionized the way we deploy and manage applications, and Microsoft Azure's Kubernetes Service (AKS) is a standout among managed Kubernetes solutions. In this post, we'll walk through how to deploy a Kubernetes cluster using AKS, manage it using Azure CLI, and deploy a sample application to the cluster.

Why Use Azure Kubernetes Service (AKS)?

  • Managed Service: AKS automates critical tasks such as provisioning, upgrading, and scaling of Kubernetes clusters.
  • Integration with Azure services: Seamlessly integrates with Azure Active Directory (AAD) for access control, Azure Monitor for logging and monitoring, and more.
  • Cost Efficiency: Only pay for agent nodes; the Kubernetes master nodes are managed by Azure and free of charge.


Step 1: Set Up Azure CLI

Log in to your Azure account via Azure CLI:

az login

If you have multiple subscriptions, set the desired subscription:

az account set --subscription "your-subscription-id"

Step 2: Create a Resource Group

Create a new resource group for your AKS cluster:

az group create --name myResourceGroup --location eastus

Step 3: Create an AKS Cluster

Create an AKS cluster in the resource group:

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys

This command creates a Kubernetes cluster named myAKSCluster with three nodes and enables monitoring and logging functions.

Step 4: Configure kubectl

To manage your new AKS cluster, configure kubectl:

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

This command merges your AKS cluster credentials with your existing kubectl configuration, allowing you to interact with your AKS cluster using kubectl commands.

Step 5: Deploy a Sample Application

Now let’s deploy a sample application to verify that our AKS cluster is functioning correctly. We’ll use a YAML file to deploy a simple Nginx web server.

Create a file named nginx-deployment.yaml with the following content:

apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
  replicas: 3
      app: nginx
        app: nginx
      - name: nginx
        image: nginx:1.16.0
        - containerPort: 80

Deploy the application using the following command:

kubectl apply -f nginx-deployment.yaml

To expose the deployment as a service and access it through a public IP, create a file named nginx-service.yaml with the following content:

apiVersion: v1
kind: Service
  name: nginx-service
  type: LoadBalancer
    app: nginx
  - protocol: TCP
    port: 80
    targetPort: 80

Deploy the service:

kubectl apply -f nginx-service.yaml

To retrieve the external IP of the service, run:

kubectl get service nginx-service

Step 6: Clean Up Resources

When you’re done experimenting, make sure to clean up your resources to avoid unnecessary costs:

az aks delete --resource-group myResourceGroup --name myAKSCluster --yes --no-wait
az group delete --name myResourceGroup --yes --no-wait


Setting up and managing a Kubernetes cluster with Azure Kubernetes Service (AKS) simplifies the operational complexity associated with Kubernetes. By leveraging Azure's integrated services, you can quickly deploy, monitor, and scale your applications. This step-by-step guide provides a practical introduction to getting started with AKS, paving the way for more complex setups and integrations.