Azure Kubernetes Service (AKS)

Your Comprehensive Guide to Getting Started

Introduction to AKS

Azure Kubernetes Service (AKS) makes it simple to deploy, manage, and scale your containerized applications using Kubernetes on Azure. AKS offers the benefits of Kubernetes without the complexity of managing the control plane or underlying infrastructure.

This tutorial will guide you through the essential steps to get your first Kubernetes cluster up and running on Azure.

Prerequisites

Before you begin, ensure you have the following:

Step-by-Step Guide

  1. Sign in to Azure

    Open your terminal or command prompt and sign in to your Azure account:

    az login

    This command will open a browser window for you to authenticate.

  2. Create a Resource Group

    A resource group is a logical container into which Azure resources are deployed and managed. You'll need to create one before creating your AKS cluster.

    Replace myResourceGroup with your desired name and eastus with your preferred Azure region.

    az group create --name myResourceGroup --location eastus
  3. Create an AKS Cluster

    Now, create your AKS cluster. This command will deploy a basic cluster with a single node pool.

    Replace myAKSCluster with your desired cluster name.

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

    This process can take several minutes.

    Note: For production environments, consider configuring multiple node pools, autoscaling, and network policies for enhanced availability and security.

  4. Connect to the Cluster

    Configure `kubectl` to connect to your AKS cluster. The az aks get-credentials command downloads credentials and configures the Azure CLI to use them.

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

    Verify that the `kubectl` connection to your cluster is successful:

    kubectl get nodes

    You should see output listing the nodes in your cluster.

  5. Deploy an Application

    Let's deploy a simple sample application to your cluster. We'll use a basic Nginx deployment.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:latest
            ports:
            - containerPort: 80

    Save the above content as nginx-deployment.yaml and apply it using:

    kubectl apply -f nginx-deployment.yaml
  6. Expose the Application

    To make your application accessible from the internet, you need to expose it using a Kubernetes Service of type LoadBalancer.

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

    Save the above content as nginx-service.yaml and apply it:

    kubectl apply -f nginx-service.yaml

    It will take a few minutes for a public IP address to be assigned to the load balancer.

  7. Access Your Application

    Get the external IP address of your service:

    kubectl get service nginx-service

    Once the EXTERNAL-IP field shows an IP address, you can access your Nginx application by opening a web browser and navigating to that IP address.

    Congratulations! You have successfully deployed and exposed a containerized application on Azure Kubernetes Service.

Next Steps

For more in-depth information, please refer to the official Azure Kubernetes Service documentation.