Azure Kubernetes Service (AKS) - Complete Guide

What is Azure Kubernetes Service (AKS)?

Azure Kubernetes Service (AKS) is a **managed Kubernetes service** that simplifies deployment, scaling, and operations of Kubernetes clusters in Azure.

Why Use AKS?

  • Fully Managed: Azure handles the Kubernetes control plane.
  • Auto-Scaling: Automatically scales nodes based on demand.
  • Integrated Security: Supports Azure AD authentication and RBAC.
  • Cost-Efficient: Pay only for the agent nodes.
  • Multi-Region Support: Deploy workloads globally.

Key Components of AKS

  • Nodes: Virtual machines running containers.
  • Pods: Groups of containers in a cluster.
  • Services: Manage external/internal network access.
  • Ingress: Controls HTTP and HTTPS traffic.
  • Persistent Storage: Stores data beyond container life cycle.

Setting Up an AKS Cluster (Step-by-Step)

Step 1: Install Azure CLI

az login

Step 2: Create a Resource Group

az group create --name MyResourceGroup --location eastus

Step 3: Create an AKS Cluster

az aks create --resource-group MyResourceGroup --name MyAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys

Step 4: Connect to AKS Cluster

az aks get-credentials --resource-group MyResourceGroup --name MyAKSCluster

Deploying an Application on AKS

Step 1: Create a Deployment YAML File

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myacr.azurecr.io/myapp:v1
        ports:
        - containerPort: 80

Step 2: Apply the Deployment

kubectl apply -f deployment.yaml

Step 3: Expose the Application

kubectl expose deployment myapp --type=LoadBalancer --port=80

Monitoring AKS Cluster

kubectl get nodes
kubectl get pods -o wide
kubectl logs pod-name
kubectl describe pod pod-name

Scaling AKS Cluster

AKS allows both **manual** and **automatic scaling**.

Manual Scaling:

kubectl scale deployment myapp --replicas=5

Auto Scaling:

az aks update --resource-group MyResourceGroup --name MyAKSCluster --enable-cluster-autoscaler --min-count 1 --max-count 5

Securing AKS

  • Enable Role-Based Access Control (RBAC).
  • Use Azure Active Directory (AAD) for authentication.
  • Apply Network Policies to control traffic.
  • Use Azure Key Vault to manage secrets.

Upgrading AKS Cluster

az aks upgrade --resource-group MyResourceGroup --name MyAKSCluster --kubernetes-version 1.23.8

Deleting an AKS Cluster

az aks delete --resource-group MyResourceGroup --name MyAKSCluster --yes --no-wait

Conclusion

Azure Kubernetes Service (AKS) provides a **fully managed, scalable, and secure** Kubernetes environment for running containerized applications in the cloud. It integrates well with Azure services and offers advanced networking, monitoring, and security features.

📌 Next Topic: Azure Blob Storage - Managing Cloud Files